【问题标题】:Conditional 301 redirect htaccess match domain and uri条件 301 重定向 htaccess 匹配域和 uri
【发布时间】:2014-04-15 09:51:01
【问题描述】:

我还有另一个重定向问题。我正在尝试向一些重定向添加条件(我在同一个文件中有 50 多个)。有效的重定向只是域条件,这意味着如果 %{HTTP_HOST} 匹配,那么它就会去。现在我正在尝试一些可以做到这一点的东西,但也只需要重定向一个特定的文件夹。这就是我所拥有的:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/some/page.php
RewriteCond %{HTTP_HOST} (^|\.) domain\.com$
RewriteRule ^ https://www.example.com/some/new/page/ [R=301,L]

简单地说,我正在尝试匹配特定域和 URI 并将其转发到新域和页面。前任: domain.com/account/blah.php

重定向到 www.example.com/some/new/page/

同时,如果没有 URI,我有另一个域重定向,它们都被指定为这样:

RewriteEngine on
RewriteCond %{HTTP_HOST} (^|\.) domain\.com$
RewriteRule ^ https://www.example.com/some/other/new/page/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/some/page.php
RewriteCond %{HTTP_HOST} (^|\.) domain\.com$
RewriteRule ^ https://www.example.com/some/new/page/ [R=301,L]

知道我做错了什么吗?

【问题讨论】:

    标签: url rewrite http-status-code-301


    【解决方案1】:
    <IfModule mod_rewrite.c>
        RewriteEngine On
        # Check domain matched but uri doesn't
        RewriteCond %{HTTP_HOST} (^|\.) domain\.com$ [NC]
        RewriteCond %{REQUEST_URI} !^/some/page.php [NC]
        RewriteRule ^ https://www.example.com/some/new/page/ [R=301,L]
    
        # Check domain matches and uri matches
        RewriteCond %{HTTP_HOST} (^|\.) domain\.com$ [NC]
        RewriteCond %{REQUEST_URI} ^/some/otherpage.php [NC]
        RewriteRule ^ https://www.example.com/some/other/new/page/ [R=301,L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2016-03-25
      • 1970-01-01
      • 2011-11-19
      • 2017-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 1970-01-01
      相关资源
      最近更新 更多