我正在寻找一个“.htaccess”文件解决方案来重写以“./index.html”结尾的请求地址和“./index”仅限于站点根或子文件夹,例如“http://www.mydomain.com/index[.html]”,直至“http://www.mydomain.com/”。我发现了一些关于“index.html”问题的帮助,但是我很难使解决方案适用于“./index”的唯一请求。我使用下面的代码与我在尝试“./index"-only片注释:.htaccess - 隐藏根目录和目录中的“/index.html”和“/ index”
# 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服务器的版本,但任何援助将不胜感激。谢谢。
第一个'RewriteRule'以及条件对我来说工作正常。你遇到的问题究竟是什么? –
感谢您的检查。我试图在第一次重写下面的double#后面得到注释代码,以匹配“/ index”和可能的“/index.html”条件,并重写URL第一次重写。否则,如果我只是得到“/ index”条件来匹配并重写为“/”,我不会介意有两个重写条件,但我不能得到任何我试图处理“/ index “条件,根本。 –