我正在更改网站的域名并执行301重定向以保持流量。
简单文件夹重定向工作正常,如下所示:
Redirect /dive-sites/ http://www.domain2.com/divesites/
但是当我尝试移动单个文件时没有任何反应,如下所示:
Redirect 301 /home.php http://www.domain2.com/home.php
知道为什么会这样吗?我尝试过其他例子没有成功:
Redirect /home.php http://www.domain2.com/home.php
Redirect 301 /home.php http://www.domain2.com/home.php
Redirect http://www.domain1.com/home.php http://www.merodivingcenter.com/home.php
Redirect 301 http://www.domain1.com/home.php http://www.merodivingcenter.com/home.php
答案 0 :(得分:2)
您是否尝试过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