【问题标题】:Use htaccess to redirect all traffic from root to specific subdomain page使用 htaccess 将所有流量从根重定向到特定的子域页面
【发布时间】:2010-10-07 08:38:10
【问题描述】:

我有一个网站已经上线了一段时间。一段时间以来,我在子域上有一个博客。我决定取消主站点,只支持博客子域。

我为此设置了重定向设置,但它会将所有额外参数传递到博客,从而导致出现找不到文件的页面。我只想重定向到不带参数的索引页面。

我目前在我的 .htaccess 文件中拥有的是这个

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?(.*)$ "http\:\/\/blog\.foo\.org\/index\.php" [R=301,L]

当我收到请求时

http://www.foo.org/foo/foo/?module=foo

它重定向到

http://blog.foo.org/foo/foo/index.php?module=foo

我希望它重定向到 http://blog.foo.org/index.php

【问题讨论】:

    标签: .htaccess mod-rewrite redirect subdomain


    【解决方案1】:
    RewriteEngine On
    Options +FollowSymlinks
    RewriteCond %{HTTP_HOST} ^(www\.)?foo\.org$ [NC]
    RewriteRule ^ http://blog.foo.org/ [R=301,L]
    

    【讨论】:

      【解决方案2】:

      您必须在替换中指定查询以覆盖原始:

      RewriteCond %{HTTP_HOST} !^blog\.example\.org$ [NC]
      RewriteRule ^ http://blog.example.org/index.php? [R=301,L]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-10
        • 2017-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-29
        • 1970-01-01
        相关资源
        最近更新 更多