【问题标题】:htaccess Rewrite Rule With Exceptionhtaccess 重写规则有异常
【发布时间】:2016-02-16 19:36:50
【问题描述】:

我想知道如何将 .htaccess 中没有参数的所有 URL 重定向到另一个 URL。

例子:

任何没有“&tag=xxx”的访问都会重定向到 index.php?tag=xxx

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    您可以在站点根目录 .htaccess 的顶部使用此规则:

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} !(?:^|&)tag=xxx(?:&|$) [NC]
    RewriteRule ^(index\.php)?$ %{REQUEST_URI}?tag=xxx [L,NC,R=302,QSA]
    

    Negative RewriteCond %{QUERY_STRING} 检查查询参数是否不存在,RewriteRule 添加缺少的查询参数并执行完全重定向。

    【讨论】:

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