1

我正在更改网站的域并进行一些 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
4

1 回答 1

2

你试过mod_rewriteRewriteRuleRewriteMatch吗?

# 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
于 2013-11-13T01:24:57.700 回答