Problem:
You have the following URLs for your website:
www.example.com/about-us.html
www.example.com/services.html
www.example.com/contact-us.html
However, you would like to hide file extensions from the end users, and allow them to access to the files using the following URLs:
www.example.com/about-us
www.example.com/services
www.example.com/contact-us
Solution:
The solution can be achieved by using Apache’s mod_rewrite. Create an .htaccess file in your website root directory with the following content.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^.]+)\.html$ $1 [L]
# Replace html with your file extension, eg: php, htm, asp
Benefits:
- Search engine friendly
- Easier to read and remember
- Extension/environment independent; when you change the technology used for your website (for eg: from using asp to php), you can be assured that all the links and bookmarks will still work.
Technorati Tags: htaccess, mod rewrite, url rewriting, nice urls, seo