2017-09-22 49 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