【问题标题】:Directory to subdomain with same name目录到具有相同名称的子域
【发布时间】:2012-06-25 03:39:00
【问题描述】:

感谢阅读。我已经进行了搜索,阅读了多个帖子(丢失计数),但仍然遇到一些看似简单的问题。 我正在尝试从以下位置重定向或重写:

http://www.mysite.com/blog/

http://www.blog.mysite.com/

首先,这应该放在根目录的htaccess文件中还是放在博客子目录中? 其次,我的一些尝试如下:

(尝试 1)

RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^blog\/?$ "http\:\/\/www\.blog\.mysite\.com\/" [R=301,L]

(尝试 2)

RewriteCond %{HTTP_HOST} ^(www\.)?blog\.mysite\.com$
RewriteCond %{REQUEST_URI} mysite.com/blog
RewriteRule ^(.*)$ /blog/$1 [L]

(尝试 3)

RewriteRule http://mysite.com/blog http://www.blog.mysite.com/$1 [R=301,L]

(尝试 4)

rewriterule ^blog/(.*)$ http://www.blog.mysite.com/$1 [r=301,nc]

非常感谢任何帮助。

【问题讨论】:

    标签: .htaccess redirect directory rewrite subdomain


    【解决方案1】:

    您的第一次尝试看起来几乎正确。我将删除OR 条件并将它们打包到一个正则表达式中,并从重写目标中删除所有转义的斜杠和引号:

    # Also, are you missing RewriteEngine On?
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
    # Redirect and place everything after /blog onto /
    RewriteRule ^blog(.*)$ http://www.blog.mysite.com$1 [R=301,L]
    

    这应该放在根目录的.htaccess中。

    【讨论】:

      【解决方案2】:

      一个简单的代码就可以做到这一点。使用

      Redirect /blog http://blog.mysite.com/
      

      【讨论】:

        猜你喜欢
        • 2020-04-11
        • 2016-01-14
        • 1970-01-01
        • 1970-01-01
        • 2015-07-23
        • 2019-03-04
        • 2016-01-05
        • 2014-04-23
        相关资源
        最近更新 更多