2017-09-22 64 views
0

我在我的.htacess文件中为我的网站删除'.html',并将任何.html重定向到同一页没有它(example.com/home.html到example.com/home)网站链接将无法使用.htaccess代码,它会删除.html扩展名

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)\.html$ /$1 [L,R=301] 

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

然而,当我试着点击那些指着我的网站其他页面的链接,我得到一个404错误。 我试过将href设置为http://www.example.com/page2,/ page2等等,但我仍然得到相同的错误。任何帮助?

回答

0

请保存你的代码,只放下面的代码在你的主目录.htaccess文件:

RewriteEngine on 
    RewriteCond %{THE_REQUEST} \s/+(.*?/)?(.*?)\.html[\s?/] [NC] 
    RewriteRule (.*)$ /%1%2 [R=302,L,NE] 

注:清除浏览器缓存,因为你做了301重定向和

+0

我改变测试代码它并没有做任何事情 – SycoSins

+0

你清除了你的浏览器缓存吗? –

+0

是的,我做到了。仍然没有。我能够访问我的主域上的多个页面,但我无法访问任何在二级域名 – SycoSins