正在使用htaccess删除路径上的.html
我想删除我所有链接末尾的正在使用htaccess删除路径上的.html,html,.htaccess,mod-rewrite,Html,.htaccess,Mod Rewrite,我想删除我所有链接末尾的.html,例如www.mywebsite.com/contact.html应该是www.mywebsite.com/contact 以下代码执行此任务: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.html [NC,L] 我还希望我的目录文件也删除.html,即www.mywebsite.com/rates/index.html应该是www.mywebsi
.html
,例如www.mywebsite.com/contact.html
应该是www.mywebsite.com/contact
以下代码执行此任务:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
我还希望我的目录文件也删除.html
,即www.mywebsite.com/rates/index.html
应该是www.mywebsite.com/rates
它正在使用以下代码:
RewriteCond %{REQUEST_URI} /index\.html?$ [NC]
RewriteRule ^(.*)index\.html?$ "/$1" [NC,R=301,NE,L]
但在一起,它们不起作用。如果第二个在第一个下面,只有第一个起作用。如果我只有第二个选项,我的第一个选项就不起作用,我的所有链接都断了。如何将两者结合起来?添加到
.htaccess
文件中
Options +FollowSymlinks -MultiViews
RewriteEngine on
# to make `/path/index.html` to /path/
RewriteCond %{THE_REQUEST} ^GET\s(.*/)index\.html [NC]
RewriteRule . %1 [NE,R=301,L]
RewriteCond %{THE_REQUEST} ^GET\s.+\.html [NC]
RewriteRule ^(.+)\.html$ /$1 [NE,R=301,L,NC]
RewriteCond %{REQUEST_URI} !\.html$ [NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule . %{REQUEST_URI}.html [L]
谢谢成功了。实际上比我想象的要复杂得多。我还不能将答案标记为正确(必须等待8分钟),但我会尽快标记为正确。