2017-01-25 123 views
1

我很難嘗試通過.htaccess刪除我們新更新的網站的.html。我已經嘗試了許多不同的代碼複製行,並從互聯網上粘貼,但我確定這很簡單,我只是沒有經驗看!將.html從.htaccess中的URL中刪除

總之,我想提出這個要求(這是一個404)掉落的.html:

http://mysite/cmt-grooving-sblade.html

要這樣:

http://mysite/cmt-grooving-sblade

任何幫助,您可以給將是我將非常感激!

到目前爲止,我的.htaccess看起來像這樣。第一部分已經在那裏,其餘的是我最近的嘗試。

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 


RewriteCond %{REQUEST_URI} \.html$ 
RewriteRule ^(.*)\.html$ $1 [R=301,L] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 
+4

可能的重複[如何從URL中刪除.html](http://stackoverflow.com/questions/5730092/how-to-remove-html-from-url) – ppasler

回答

0

試試這個;

RewriteEngine on 

# if a directory or a file exists, use it directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# otherwise forward it to index.php 
RewriteRule . index.php 

RewriteCond %{HTTP:Authorization} ^(.*) 
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] 
+0

謝謝你的答案。這將刪除.html?在我的.htaccess中,代碼的第一部分起作用(據我所知),但這是使我酸洗的.html文件。 – Darran

1

您可以用它來從您的網址中移除.html

RewriteEngine on 

RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC] 
RewriteRule^/%1 [NC,L,R] 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule^%{REQUEST_URI}.html [NC,L] 

它會離開你你想要的網址:http://mysite/cmt-grooving-sblade。確保在測試之前清除緩存。

+0

這應該工作。 +1 – starkeen

+0

非常感謝您的幫助,但不幸的是,這似乎並不奏效。我懷疑我可能會把它放在錯誤的地方。 在我的.htaccess中,我把它粘貼在底部,正好在其他代碼下面(我很猶豫,因爲它在那之前我就開始玩弄它了!) 我試過它,沒有重寫引擎,因爲我看到它是從上面的代碼開始的,最後我有。你會用錘子打我,因爲我確定這是我的錯誤! – Darran

+0

我應該澄清。目前該網站在任何網站上都沒有顯示.html,但是舊網站卻顯示.html。我有來自Google的404s正在尋找.html鏈接,我想要做的就是直接提交所有的.html請求,以放棄.html,它將登陸正確的頁面。非常感謝迄今爲止的幫助。 – Darran