1

我有一个用 Rails 重写的应用程序。旧应用程序在 php 中。

我需要将所有 php 请求重定向到子域 old.example.com(我已将旧应用程序放在那里运行),以便旧链接仍然有效。我相信所有链接中都有一个“.php”,而我的新网址都没有。所以它可以用作重定向的条件。

我计划使用 apache RedirectMatch。所以像:

RedirectMatch \.php http://old.example.com

应该很近。我相信。我只是不知道如何将请求路径传递给重定向规则。

或者如果有人有更好的想法如何做到这一点?

4

1 回答 1

1

使用 Apache mod rewrite,您将使用以下内容:

RewriteEngine On
RewriteBase /
RewriteRule ^.*\.php.*$ http://old.example.com/index.php [R=301,NC]

如果您想在重定向 URL 中实际插入他们试图访问的页面:

RewriteEngine On
RewriteBase /
RewriteRule ^/?(.*)\.php.*$ http://old.example.com/$1.php [R=301,NC]

$1将在括号中插入与正则表达式匹配的任何内容。

对于 GET 参数:

RewriteEngine On
RewriteBase /
RewriteRule ^/?(.*)\.php(.*)$ http://old.example.com/$1.php$2 [R=301,NC]
于 2012-07-11T13:33:06.677 回答