Access Pages Without the PHP Extension Using .htaccess

There are a number of ways to make "clean URLs" work on your site, but this one is pretty straight forward.  It allows you to access /any-page.php by simply going to /any-page.  Just place the following into your .htaccess file (and make sure that mod_rewrite is enabled):

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]

The nice thing about this is that it doesn't affect querystrings.  With this solution, both of these URLs are effectively the same:

http://example.com/page.php?id=123
http://example.com/page?id=123

Of course, the caveat is that you don't have "clean querystrings", but it's a reasonable trade-off between "clean" and configuration.

Thanks for Reading

If you found this post helpful, please check out my service Surreal CMS. It’s a hosted content management system with beautiful inline editing and a ton of other great features!

Author avatar

About the author

Cory LaViska is a founder, web developer, and bootstrapper based in Orlando, Florida. Need to get in touch? You can connect with him on Twitter. Looking for a simple, no-worry CMS for your clients? Try my Surreal CMS!