使用Apache RedirectPermanent将所有请求发送到特定的子文件夹

在早些时候问了一个冗长而复杂的问题之后,我现在使用了RedirectPermanent一些代码,我需要帮助。

我们正在合并一个旧的网站到新的一个,并不关心映射所有的古代url到新址的任何地方,所以它应该永久redirect到一个特殊的index.php将决定是否/在哪里redirect与PHP。

例外是一个子域,它应该做同样的事情,但不同的index.php。

这是我试图完成的“伪configuration” – 轻微的变化将工作,但我不能让它忽略请求的完整path,并无条件地去我的select与查询string的index.php。

 #Subdomain from old site: #Process querystring from root\oldsite\subdomain\index.php <VirtualHost *:80> ServerName subdomain.oldsite.com RedirectPermanent / http://www.newsite.com/oldsite/subdomain/index.php </VirtualHost> #ALL other requests of any kind regardless of path #Process querystring from root\oldsite\index.php # Must show www.newsite.com, NOT www.oldsite.com <VirtualHost *:80> ServerName oldsite.com ServerAlias www.oldsite.com RedirectPermanent / http://www.newsite.com/oldsite/index.php </VirtualHost> 

已经设置了DNS,以便从旧站点的所有内容都进入该服务器,这些是configuration文件中的第一个VirtualHost条目。 我如何修改这个代码去给定的index.php, 不pipepath。

 www.oldsite.com ==> www.newsite.com\oldsite\index.php www.oldsite.com/forum/anything/else ==> www.newsite.com\oldsite\index.php www.oldsite.com/faq/category/chosen ==> www.newsite.com\oldsite\index.php www.oldsite.com/about/us/index.php ==> www.newsite.com\oldsite\index.php subdomain.oldsite.com/anthing ==> www.newsite.com\oldsite\subdomain\index.php 

redirect不是正确的用于你所寻求的。 redirectredirect“全部”和“追加所有”的目的地,但你想要一个最终的单一目的地,所以..用这个,而不是:

 RedirectMatch ^ http://newsite.example.com/oldsite/subdomain/index.php 

这会将所有内容redirect到您指定的目的地,而不会附加任何其他内容。