【问题标题】:How can I 301 redirect specific subdomain URLs using .htaccess?如何使用 .htaccess 301 重定向特定的子域 URL?
【发布时间】:2012-03-23 19:06:42
【问题描述】:

我需要将子域上的特定 URL 重定向到不同子域上的完全不同的 URL。例如:

http://foo.example.com/this-is-my-page

需要301到:

http://bar.example.com/this-is-really-my-page

我尝试在.htaccess 中设置一个简单的Redirect 301,但它似乎不起作用。例如:

Redirect 301 http://foo.example.com/this-is-my-page http://bar.example.com/this-is-really-my-page

【问题讨论】:

  • 可能需要在 apache 配置中的其他位置。你用的是什么操作系统?

标签: apache .htaccess mod-rewrite redirect


【解决方案1】:

试试这个:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*) http://newsub.domain.com/ [L,R]

对我有用

【讨论】:

    【解决方案2】:

    这是我最终做的:

    # first re-write all foo.example.com requests to bar.example.com
    RewriteCond %{HTTP_HOST} ^foo\.example\.com [NC]
    RewriteRule (.*) http://bar.example.com/$1 [L,R=301]
    
    # now re-write each individual URL
    RewriteRule ^this-is-mypage /this-is-really-my-page [NC,L,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-10
      • 1970-01-01
      • 2019-12-15
      • 2017-03-17
      • 1970-01-01
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多