【问题标题】:.htaccess | no redirect if there is an specific parameter.htaccess |如果有特定参数,则不重定向
【发布时间】:2013-09-02 21:23:04
【问题描述】:

我现在正在做一个 cms 现在我正在为 ajax 实现而苦苦挣扎

除了 mod_rewrite 问题外,我什么都在运行..

RewriteEngine On
RewriteRule \.html index.php [L]

这只会将 html 文件重定向到 index.php

我需要第二条规则来检查 REQUEST_URI 的参数,以防止 ajax 加载整个站点。

我不认为这是可以理解的,所以我只是发布我想要实现的目标^^

RewriteEngine On
RewriteCond %{REQUEST_URI} !(?rewrite=no$)
RewriteRule \.html index.php [L]

除了 html 文件外,我不希望任何重定向,并且在 url 上也不要重定向,末尾带有“(.html)?rewrite=no”

希望有人可以帮助我,因为重写和正则表达式不是我最擅长的东西

提前致谢

【问题讨论】:

  • 您的描述有点令人困惑 - 您说您当前正在将所有 except .html 文件重定向到 .index.php,但您现有的规则现在重写了 .html 请求。你是这个意思吗?
  • 哎呀,必须改变它

标签: .htaccess redirect mod-rewrite parameters rewrite


【解决方案1】:

来自the Apache docs

REQUEST_URI 请求的 URI 的路径组件,例如“/index.html”。这特别排除了查询字符串,该字符串可作为其自己的名为 QUERY_STRING 的变量使用。

因此,您实际上是在寻找匹配 %{QUERY_STRING} 而不是 %{REQUEST_URI}。匹配条件时不要在查询字符串中包含?

RewriteEngine On
# Match the absence of rewrite=no in the query string
RewriteCond %{QUERY_STRING} !rewrite=no [NC]
# Then rewrite .html into index.php
RewriteRule \.html index.php [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-28
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多