小编GDP*_*GDP的帖子

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

之前问了一个又长又复杂的问题,现在我这里有一些代码RedirectPermanent需要帮助。

我们正在将旧站点合并到新站点中,并且不关心将所有古老的 url 映射到新站点上的任何位置,因此所有这些都应该永久重定向到一个特殊的 index.php,它将决定是否/在哪里使用 php 进行重定向。

一个子域是例外,它应该执行相同的操作,但针对不同的index.php。

这是我试图完成的“伪配置” - 轻微的变化会起作用,但我无法让它忽略请求的完整路径,并无条件地使用查询字符串转到我选择的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>
Run Code Online (Sandbox Code Playgroud)

DNS 已设置,以便旧站点中的所有内容都转到此服务器,这些是配置文件中的第一个 VirtualHost 条目。我如何修改此代码以转到给定的index.php,无论路径如何。

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
Run Code Online (Sandbox Code Playgroud)

redirection 301-redirect apache-2.4

3
推荐指数
1
解决办法
7835
查看次数

标签 统计

301-redirect ×1

apache-2.4 ×1

redirection ×1