Dave Dave - 1 month ago 5
HTML Question

How to remove .html from URL

Do you have any idea how to remove .html from the URL of a static page. Also, I need to redirect any url with .html to the one without (ie. www.example.com/page.html to www.example.com/page).

Answer

Thanks for your replies. I have already solved my problem. Suppose I have my pages under http://www.yoursite.com/html, the following .htaccess rules apply.

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*).html\ HTTP/
   RewriteRule .* http://localhost/html/%1 [R=301,L]

   RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*)\ HTTP/
   RewriteRule .* %1.html [L]
</IfModule>