你试过mod_rewrite
和RewriteRule
或RewriteMatch
吗?
# Enable mod_rewrite, set base
RewriteEngine On
RewriteBase /
#Rewrite home.php
RewriteRule ^home\.php http://www.domain2.com/home.php [R=301]
# Rewrite all other PHP pages (including directory path)
RewriteRule (.*?\.php)$ http://www.domain2.com/$1 [R=301]
在http://htaccess.madewithlove.be/上测试
output url
http://example.com/home.php
output url
http://www.domain2.com/home.php
debugging info
1 RewriteEngine On
2 RewriteBase /
3 RewriteRule ^home\.php http://www.domain2.com/home.php [R=301]
This rule was met, the new url is http://www.domain2.com/home.php
The tests are stopped, using a different host will cause a redirect
4 RewriteRule (.*?\.php)$ http://www.domain2.com/$1 [R=301]
input url
http://example.com/foo/bar.php
output url
http://www.domain2.com/foo/bar.php
debugging info
1 RewriteEngine On
2 RewriteBase /
3 RewriteRule ^home\.php http://www.domain2.com/home.php [R=301]
4 RewriteRule (.*?\.php)$ http://www.domain2.com/$1 [R=301]
This rule was met, the new url is http://www.domain2.com/foo/bar.php
The tests are stopped, using a different host will cause a redirect