【问题标题】:Redirecting Subdomain to an IP Without www将子域重定向到没有 www 的 IP
【发布时间】:2011-11-14 02:36:30
【问题描述】:

我尝试了几个小时,几乎要生气了。我想将我的 sub.example.com 重定向到远程服务器文件上的一个文件。

所以我想将我的子域(带 www/不带 www)重定向到 x.x.x.x/example/photo.jpg

www.sub.example.com 一切正常。它完美地重定向到 x.x.x.x/example。 说到 sub.example.com,我有 404。

RewriteEngine on

RewriteCond %{HTTP_HOST} ^sub\.example\.com$
RewriteCond %{HTTP_HOST} ^www\.sub\.example\.com$
RewriteRule ^(.*)$ "http\:\/\/x\.x\.x\.x\/example/$1" [R=301,L]

【问题讨论】:

    标签: apache .htaccess redirect subdomain


    【解决方案1】:

    RewriteCond 隐含地“与”在一起,这意味着您永远不会得到一个同时是“sub.example.com”和“www.sub.example.com”的 %{HTTP_HOST},因此RewriteRule 永远不会被使用。您可以在第一个之后添加[OR]

    RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.sub\.example\.com$
    

    这样要么 RewriteCond 可以被满足并且规则将被使用,或者只是使用这个:

    RewriteCond %{HTTP_HOST} ^(www\.)?sub\.example\.com$
    

    这实质上是在说“www”。在比赛中可以是可选的。

    【讨论】:

      【解决方案2】:

      cliknfind website

      使用此代码 RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [NC] 重写规则 ^(.*)$ http://www.example.com/$1 [R=301,L]

      【讨论】:

        猜你喜欢
        • 2014-03-25
        • 1970-01-01
        • 2018-04-07
        • 2012-04-01
        • 2013-09-18
        • 1970-01-01
        • 2015-05-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多