我有以下网站结构:
的index.html
/assets/subpage.html
/assets/secondpage.html
我在.htaccess中写了以下规则:
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/assets
RewriteRule (.*) /assets/$1 [QSA,L]
我想从文件中删除.html(第一条规则),我想跳过/资产(第三条和第四条规则)。但是我想从3 i 4规则中排除.index.html。现在当我输入:
www.example.com它将我重定向到www.example.com/assets/.html(我希望这个将我重定向到www.example.com) 当我输入www.example.com/subpage时,它会将我重定向到:www.example.com/assets/subpage.html
我该如何解决?
答案 0 :(得分:0)
您可以使用:
DirectoryIndex index.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^.]+)$ $1.html [NC,L]
RewriteCond %{REQUEST_URI} !^/(index\.html$|assets/) [NC]
RewriteRule (.+) assets/$1 [L]
RewriteCond
,以确定是否存在.html
文件.+
确保我们与目标网页不匹配