在`foo`中redirect`foo /`到foo / bar /`

可能重复:
一切你想知道Mod_Rewrite规则,但不敢问?

我有一个文件夹~/Branches/可以通过localhost/~me/ apache2访问。 现在我有localhost/~me/branches_index/web/index.php ,我想在localhost/~me/branches_index/

那么我怎么能从/Branches/branches_index/文件夹中的/Branches/branches_index/ /~me/branches_index/web/redirect


我试过了,但是我没有成功。

无尽的循环:

 Redirect /~me/branches_index/ /~me/branches_index/web/ 

/web/在前面:

 Redirect / /web/ 

您尝试redirect失败,因为
Redirect /~me/branches_index/ /~me/branches_index/web/
会recursion地redirect/~me/branches_index/*

这意味着/~me/branches_index/what/so/ever
将被redirect到/~me/branches_index/web/what/so/ever因此,你最终会陷入一个无休止的循环。

解决方法是在.htaccess文件中使用重写,保存在/~me/branches_index/
像这样的代码应该做的工作:

 RewriteEngine on RewriteCond %{REQUEST_URI} !^(.*)web/(.*)$ RewriteRule ^(.*)$ /~me/branches_index/web/$1 [NC,L] 

一种方法是将其放在/ branches_index / .htaccessconfiguration中,

 RewriteEngine On RewriteCond %{REQUEST_URI} !^web/ RewriteRule (.*) web/$1 [QSA,L]