Php 使用.htaccess重定向特定URL

Php 使用.htaccess重定向特定URL,php,.htaccess,redirect,Php,.htaccess,Redirect,如何像这样重定向网站: www.old.com/test.php -> www.new.com/test.php 但请输入www.new.com/ www.new.com/test1.php -> www.old.com/test1.php www.new.com/test2.php -> www.old.com/test2.php www.new.com/test3.php -> www.old.com/test3.php 如果文件名不按顺序排列,例如: www.n

如何像这样重定向网站:

www.old.com/test.php -> www.new.com/test.php
但请输入
www.new.com/

www.new.com/test1.php -> www.old.com/test1.php
www.new.com/test2.php -> www.old.com/test2.php
www.new.com/test3.php -> www.old.com/test3.php
如果文件名不按顺序排列,例如:

www.new.com/home.php -> www.old.com/aiej.php
www.new.com/contactus.php -> www.old.com/contact.php
www.new.com/aboutus.php -> www.old.com/aboutus.php
www.new.com/msdv.php -> www.old.com/msdv.php
只有
test.php
将重定向到
www.new.com/
,其他人将重定向回
www.old.com


我更喜欢使用
.htaccess
文件。有什么建议吗?

在您的
.htaccess

RewriteEngine On
RewriteBase /

# Redirect test.php to new
RewriteCond %{HTTP_HOST} ^www\.old\.com$ [NC]
RewriteRule ^(test)\.php$ http://www.new.com/$1.php [R=301,L]

# Redirect test* to old
RewriteCond %{HTTP_HOST} ^www\.new\.com$ [NC]
RewriteRule ^test(.+)\.php$ http://www.old.com/test$1.php [R=301,L]

您必须手动定义文件名以重定向到旧站点。
RewriteCond %{HTTP_HOST} ^www.new.com$
RewriteRule ^test(1|2|3)\.php$ http://www.old.com%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www.old.com$
RewriteRule ^test\.php$ http://www.new.com%{REQUEST_URI} [R=301,L]