Removing file extension via .htaccess

To make the following URL :

www.example.com/about-us.html

to

www.example.com/about-us

we need to rewrite the htaccess. We have an easy method to rewrite all the files with just one code.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Replace html with your file extension, eg: php, htm, asp


At times, we might have issue with the code because of the server configuration. In case the above code fails, try the one below.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

If there are few links to rewritten instead of the whole site, Please use

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^index\.html$ home.html
RewriteRule ^about-us\.php$ about-us.html


Related Posts Plugin for WordPress, Blogger...

Comments

Total Views :4,212
avatar

About Moviefreak