重定向到子目录,子目录出来的
-
23-09-2019 - |
题
我有一个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,因为该网站托管externaly和我有到apache的configs没有访问。
非常感谢任何指针。
解决方案
检查 HTTP请求行在< EM> THE_REQUEST 代替:
RewriteCond %{THE_REQUEST} ^GET\ /net[/? ]
RewriteRule ^net($|/(.*)) /$2 [L,R=301]
不隶属于 StackOverflow