我正在尝试从我的登录页面中删除.html
,一个例子不是domain.com/contact.html
它会domain.com/contact
同时保留网站内所有文件夹的.html
,所以domain.com/components/file.html
会保留为.html
..
所以换句话说,重定向到登陆页面,而不是我的服务器上的所有其他文件。
这是我当前用于删除.html
的代码,但它也为所有其他目录删除了它。
#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,QSA]
#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]
有人对此事有任何建议吗?
谢谢。
试试这段代码:
DirectorySlash Off
RewriteEngine On
RewriteCond %{THE_REQUEST} s/+(.*?/)?(?:index)?(.*?).html[s?/] [NC]
RewriteRule ^(.[^/]*)$ /%1%2 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*) /$1.html [L]