Stripping out .html from your URLs
Just learned this little trick in apache’s .htaccess file to strip out the trailing .html from my URLs:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html |
After adding the above lines to the .htaccess file, when I request for http://nareshjain.com/about it automatically serves http://nareshjain.com/about.html page. It also handles named anchor’s very well. For example http://nareshjain.com/services/clients#testimonials works perfectly fine as well.
Rationale behind this:
- My URLs are shorter
- Gives me the flexibility to use some web-framework to serve my pages in future.