Remove .php from URLs [Snippet]

When making custom sites, I separate my code into various php files that each include a consistent header and footer so that I don’t have to deal with verbose, redundant HTML files. By default you end up with gross URLs like mysite.com/contact.php. Make it mysite.com/contact by adding this to your .htaccess file and replacing index|about|..…


When making custom sites, I separate my code into various php files that each include a consistent header and footer so that I don’t have to deal with verbose, redundant HTML files. By default you end up with gross URLs like mysite.com/contact.php. Make it mysite.com/contact by adding this to your .htaccess file and replacing index|about|.. with your own page names. There’s probably a more efficient way, but this works fine for small sites.

RewriteEngine On
RewriteRule ^(index|about|plans|app|features)/?$ $1.php?%{QUERY_STRING} [L]

If you do like verbose, redundant HTML files, I imagine you could just change the .php in the snippet above to .html. Enjoy!