Removing file extensions using htaccess 05-14-2013, 11:24 PM
#1
Simple tutorial to remove annoying extensions from your URL, makes everything more user and search engine friendly. Gotta show your URLs some love, don't force them to have those god damn ugly extensions!!
Everything I mention in this tutorial goes in a new file named .htaccess which should be placed in your root folder.
The code above removes .php and .html extensions, you can copy the entire code and paste it in again changing the values to remove any kind of extensions.
The code above adds a trailing slash after the URL, so aboutus.php would become aboutus/ - w00t.
Short and sweet. Just remember you will need to change all of your affected URLs to remove the extensions.
Everything I mention in this tutorial goes in a new file named .htaccess which should be placed in your root folder.
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.phpThe code above removes .php and .html extensions, you can copy the entire code and paste it in again changing the values to remove any kind of extensions.
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]The code above adds a trailing slash after the URL, so aboutus.php would become aboutus/ - w00t.
Short and sweet. Just remember you will need to change all of your affected URLs to remove the extensions.
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)