我试图用 htaccess 屏蔽 html 和 shtml 文件的文件扩展名。我对htaccess了解不多,我设法做的是删除扩展名,将尾部斜杠添加到shtml页面,然后停在那里。我也想在 html 文件中添加斜杠,但我对该主题的研究让我无处可去。看起来我要么生成一个带有两个斜杠的 url,要么生成一个带有假目录、斜杠和文件扩展名的 url,或者由于某种奇怪的原因而丢失了页面的样式。
我基本上已经尝试了我所知道的一切。这是我所拥有的:
#this redirects idex.html to http://mysite.com
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://%{HTTP_HOST}/ [R=301,L]
#remove file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# if I try this (.*)/$ $1.html the page loses its style
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.shtml -f
RewriteRule ^(.*)/$ $1.shtml
#the code above for shtml files works properly
#force trailing slash and remove file ext. This produces error
#RewriteCond /%{REQUEST_FILENAME}.html -f
#RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1
##the code below is perfect (retrieved on StackExchange)
#RewriteCond %{REQUEST_URI} (.*)/$
#RewriteCond %{REQUEST_FILENAME}\.html -f
#RewriteRule (.*)/$ $1.html [L]
#especially if combined with this, but pages lose their style
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME}\.html -f
#RewriteRule .* %{REQUEST_FILENAME}/ [R=301,L]
有没有办法添加斜杠并保持页面的样式?我确定有一个,但我似乎无法找到它...在此先感谢