【问题标题】:htaccess 301 redirect to different domainhtaccess 301 重定向到不同的域
【发布时间】:2013-03-01 14:27:51
【问题描述】:

相信我,我已经到处寻找解决问题的方法,所以我不认为这是一个重复的问题。

我需要做以下事情:

301 将 blog.example.com 重定向到 blog.newexample.com。

我所拥有的已经接近工作了。当我转到 blog.example.com 的主页时,它会完美地重定向到 blog.newexample.com。但是,如果我访问 blog.example.com/directory/page,它不会将我定向到 blog.newexample.com/directory/page。

这是我的 .htaccess 的样子:

# 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]

RewriteCond %{HTTP_HOST} !newexample.com$ [NC]
RewriteRule ^(.*)$ http://blog.newexample.com/$1 [L,R=301] 
</IfModule>

# END WordPress

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    我不确定你的问题是什么,但这很好用:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} !newexample.com$ [NC]
    RewriteRule ^(.*)$ http://blog.newexample.com/$1 [L,R=301] 
    </IfModule>
    

    URL http://website.com/hello/world/ 将我重定向到 http://blog.newexample.com/hello/world/.

    【讨论】:

    • 我不想更改 website.com/hello/world。我想将 blog.website.com/hello/world 更改为 blog.newexample.com/hello/world。我基本上只是想更改域。子域和路径需要保持不变。
    • 其实只是放了一个通用的网站 URL,但我在自己的 subdomain.domain.tld/somedir/hello/world 上进行了尝试,并且成功了。它应该适用于任何域和子域,例如您的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 2013-09-30
    相关资源
    最近更新 更多