Domanda

I'm doing a new version of my website. Google has crawled my website. The url of all pages are written like this : http://www.domain.com/url-page

In my new version of my website, the url will be : http://www.domain.com/url-page.html

How do you do with the .htaccess the 301 redirection of all url without extension to .html please ?

But, the rule must not add .html to url if it's a directory (ended with /)

thanks you for your help

È stato utile?

Soluzione

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(/|\..+)$
RewriteRule ^ %{REQUEST_URI}.html [L,NC,R]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top