我想要做的是删除.html的URL友好网站。这是我的.htaccess:
RewriteCond %{THE_REQUEST} \s/+rscares/(.*?)\.html[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
#example.com/page will display the contents of example.com/page.html
RewriteEngine On
RewriteBase /rscares/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
这就是问题,我正在子文件夹进行测试,所以如果我输入example.com/folder/page
工作正常,但如果我example.com/folder/page.html
它重定向到{{1我得到一个 404 ,因为该页面不存在。我想重定向到重定向之前的相同标签。有帮助吗?感谢。
答案 0 :(得分:1)
您可以使用此代码:
RewriteEngine On
RewriteBase /rscares/
RewriteCond %{THE_REQUEST} \s/+(rscares/.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]