Remove File Ext From URL Using HTAccess

htaccess

This is a way to change a URL from something like http://www.hellojosh.com/contact.php to http://www.hellojosh.com/contact/ without changing your existing code using HTAccess.

				RewriteCond %{HTTP_HOST} ^www\.hellojosh\.com$ [NC]
				RewriteRule ^(.*)/$ /$1.php [NC,L]
			

So what is happening is that it checks to see if the HTTP Host is www.hellojosh.com then it will take anything before the last slash and rewrite so that it shows the information from the respective .php page. So if you type in www.hellojosh.com/contact/ it will show the info from the www.hellojosh.com/contact.php file.

The NC at the ends of the lines tells Apache to not be case sensitive and the L tells Apache to not apply anymore rules after it applies that rule.