【问题标题】:Apache ModRewrite pattern not storedApache Mod_Rewrite 模式未存储
【发布时间】:2012-04-17 16:01:19
【问题描述】:

我不明白为什么下面的方法不起作用

RewriteCond ${foobar:test:$1} ^
RewriteRule ^/?(.*)$ /check.php?url=$1 [L]

foobar 是一个程序(简单的 bash 脚本),我在其中写入文件以查看输入内容。 check.php 是一个简单的 php 脚本,它显示 GET 的内容。这是我将正则表达式 ($1) 传递给 shell 脚本和 php 脚本时得到的结果:

url                          check.php             foobar

www.example.com/index.html   index.html            test:
www.example.com/index.php    index.php             test:
www.example.com/test.html    test.html             test:

基本上,模式在 RewriteRule 中被识别,但不是 foobar 的参数。

注意:shell 脚本没有任何问题。相反,如果我这样称呼它${foobar:test:abc123},则输出为“test:abc123

【问题讨论】:

    标签: regex bash mod-rewrite lamp


    【解决方案1】:

    在我看来:

    RewriteCond ${foobar:test:$1} ^
    

    第一个 $1 是无意义的,因为 $1 应该引用前面的表达式,例如:

    RewriteRule ^/?(.*)$ /check.php?url=$1 [L]
    

    所以我不明白这是如何工作的,如果有什么工作,那就……奇怪了。

    http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritemap

    可能是这样的:

    RewriteRule ^(.*)$ ${foobar:test:$1} [R,L,NC]
    

    可以工作。

    【讨论】:

      猜你喜欢
      • 2016-02-19
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多