我正在使用下面的.htaccess删除.html文件的扩展名,但如果有人input
example.com/test
到它redirect到的浏览器
http://www.example.com/test.html
。
为什么.html被添加并且不被删除?
RewriteEngine on RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^([^/]+)/$ $1.html
做replace的行是
RewriteRule ^([^ /] +)/ $ $ 1.html
这将无条件地将.html添加到任何请求,其中主机名后面的唯一斜杠是最后一个字符(例如http://example.com/test/ ,而不是http://example.com/test1/test2/ )。
如果你想剥离.html ,试试这个:
RewriteRule(。*)\。html $ $ 1