【问题标题】:Redirect from old domain to new domain not work从旧域重定向到新域不起作用
【发布时间】:2015-04-08 18:48:51
【问题描述】:

我尝试从旧域重定向到新域,通过下面的代码,但不起作用,哪里出错了。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteRule ^/?$ "http\:\/\/mydomain\.com\/" [R=301,L]
</IfModule>

# END WordPress

【问题讨论】:

    标签: php wordpress apache .htaccess mod-rewrite


    【解决方案1】:

    你需要在 WP catch-all 规则之前放置重定向规则,否则你只会在新域重定向后得到index.php

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
    RewriteRule ^ http://newdomain.com%{REQUEST_URI} [NE,R=301,L]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-23
      • 2011-09-23
      • 2021-04-14
      • 2016-06-24
      • 1970-01-01
      相关资源
      最近更新 更多