【发布时间】:2010-03-30 05:56:25
【问题描述】:
我有一个我无法弄清楚的 mod_rewrite 重定向问题。
来自特定域的所有请求都会“静默”地重写到指定的子目录中。例如www.mydomain.net/hello.html 检索 /net/hello.html 中的文件。以下 .htaccess (放置在我的托管根目录中) 完美地实现了这一点:
RewriteEngine on
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200 # <-- i will need this later. read to the end of the post.
RewriteRule .* - [L]
rewriteCond %{HTTP_HOST} ^www.mydomain.net$
rewriteCond %{REQUEST_URI} !^/net.*$
rewriteRule (.*) /net/$1 [L]
然而,直接进入该目录的 URL 应该以 301 明显地重定向到 没有 该子目录的 URL。例如www.mydomain.net/net/hello.html 应该重定向到www.mydomain.net/hello.html(它仍然会在/net/hello.html 中检索文件)。我的 .htacces 文件(放在 /net) 不幸的是不起作用:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^(.*) /$1 [R=301,L]
尽管根 .htaccess 文件中有 RewriteCond %{ENV:REDIRECT_STATUS} 200 块,但我得到了一个不定式重定向循环......所以出了什么问题?
顺便说一句,我必须使用 mod_rewrite,因为该站点是外部托管的,我无权访问 apache 配置。
非常感谢您的任何指点。
【问题讨论】:
标签: apache .htaccess mod-rewrite redirect infinite-loop