Kaßta Kaßta - 2 months ago 11x
Apache Configuration Question

Remove .html from URLs with a redirect

We have a website, unfortunately all the URLs have the

suffix, its a Magento installation, Magento allows you to change this on the CMS, but again, unfortunately all this URLs with
suffix have a good ranking in Google. We need to redirect to non

So, consider the following scenario, we are rebuilding this site from scratch, so we have the same urls on the new site but without the .html suffix.

  • Now is:

  • Will be:

will not exist anymore, and I've been trying a redirect with the .htaccess with no luck.

I've tried so far:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule (.*)index\.html$ /$1 [R=301,L]


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

but it doesn't seem to work...any ideas?


Ok so, after some research, and failing to achieve this with a rewrite rule, the following line of code worked:

redirectMatch 301 ^(.*)\.html $1

This is quite usefull to remove any url extension and avoid broken links, hopefully helps someone in the future...