简体   繁体   中英

.htaccess redirection none extension to .html

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM