【问题标题】:Rewrite only one specific url只重写一个特定的 url
【发布时间】:2013-08-07 11:25:58
【问题描述】:

我想重写一个特定的 url。

http://example1.com 应该是http://example2.de。

但http://example1.com/subdir 或http://sub.example1.com 应该保持不变。

我找到了以下,成功重写了example1.com,但也重写了每个以example1.com开头的url

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^example.com [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

背景:我想重定向 WP-Multisite 的主页,但想确保我可以使用 wordpress 的后端并运行其他作为子域的多站点。

【问题讨论】:

    标签: .htaccess redirect rewrite


    【解决方案1】:

    对于仅匹配 http://example.com 域(不可能在 example.com 之前或之后添加任何内容),请使用以下代码:

    RewriteCond %{HTTP_HOST} ^(example.com(\/{0,1})){1}$
    RewriteRule http://example2.de(\/{0,1}) [R=301,L]
    

    (\/{0,1}) 部分用于匹配 example.com 和 example.com/(但没有任何内容) - 如果您不想匹配 example.com/,请从两行中删除该部分。

    【讨论】:

      【解决方案2】:

      您已经很接近了,但您不需要在 $1 中捕获 URI:

      Options +FollowSymLinks -MultiViews
      # Turn mod_rewrite on
      RewriteEngine On
      
      RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com$ [NC]
      RewriteRule ^$ http://example2.de/ [L,R=301]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多