我正在寻找一种“.htaccess”文件解决方案,以将请求的以“./index.html”和“./index”结尾的地址重写为仅站点根目录或子文件夹,例如“http://www. mydomain.com/index[.html]" 降到只有 " http://www.mydomain.com/ "。我在“index.html”问题上找到了一些帮助,但我很难使解决方案适用于“./index”-only 请求。我正在使用以下代码尝试注释掉“./index”-only 部分:
# MOD_REWRITE IN USE
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# Redirect "index" page requests to either root or directory
# These first two lines work for "./index.html"...
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://%{HTTP_HOST}/ [R=301,L]
## These three lines don't work, last two are alternates of one another...
## RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index*\ HTTP/
## RewriteRule ^index*$ http://%{HTTP_HOST}/ [R=302,L]
## RewriteRule ^index*$ $1 [R=302,L]
# Hide .html extension - additional information
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L]
# To internally forward /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [L]
(如前所述,后一部分用于隐藏“.html”结尾,可能是多余的,但我按原样包含了整个脚本。)我不知道 Apache 服务器的版本,但任何帮助将不胜感激. 谢谢。