【问题标题】:I can not understand apache rewrite which use $1 in rewriteCond我无法理解在 rewriteCond 中使用 $1 的 apache rewrite
【发布时间】:2013-08-28 12:41:04
【问题描述】:

例如:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

我无法理解 RewriteCond 中 $1 的含义。

如果$1指定给RewriteRule的(.*),那么我们可以在RewriteCond中这样使用吗?

【问题讨论】:

    标签: regex apache mod-rewrite


    【解决方案1】:

    是的$1 对应于您的RewriteRule 中的第一个匹配组。这通常是为了防止无限循环(Apache 中可怕的内部 500 错误)。

    PS:这里可能不需要这个条件,因为你之前已经有RewriteCond %{REQUEST_FILENAME} !-f

    【讨论】:

    • 使用捕获组引用不会阻止无限循环,任何通常使用它的人都是错误的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多