代码之家  ›  专栏  ›  技术社区  ›  Aron Rotteveel

Dual.htaccess:$\u获取变量清空。我能做什么?

  •  1
  • Aron Rotteveel  · 技术社区  · 14 年前

    我目前正在从事一个项目,其中我的Apache documentroot与我的索引.php居住。奇怪的是,由于这个设置,我的$\u GET superglobal似乎被清空了。

    目录结构:

    • /文档根
    • /Documentroot/.htaccess文件
      • /公共/.htaccess
      • /公开/索引.php

    第一次之后出现问题。htaccess已处理。

    #First .htaccess in Apache documentroot:
    RewriteEngine On
    RewriteRule (.+) public/$1 [NC,L]
    
    # Second .htaccess in /documentroot/public:
    SetEnv APPLICATION_ENV testing
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    

    一些观察结果:

    • 当你在公众场合抛售美元时/索引.php文件,它是空的
    • 打电话的时候索引.php像/?foo=bar,$\u GET为空
    • 打电话的时候索引.php就像/index.php?foo=bar$\u GET已填充

    是什么导致$GET变量被清空?

    编辑:事情变得非常奇怪:

    2 回复  |  直到 14 年前
        1
  •  0
  •   Matt Bridges    14 年前

    我猜在这里,但当要求 /?foo=bar

    /?foo=巴 public// ,将被重写为 index.php 按照你的最后一条规则。也许试试 ^/?(.*)$ 作为你的第一个模式。

        2
  •  0
  •   William Linton    14 年前

    事情是这样的:

    1. 你的要求 /?foo=bar
    2. RewriteRule documentroot/.htaccess 重定向到 public/?foo=bar
    3. public/.htaccess ,的 RewriteCond 检查它是文件、符号链接还是目录。绳子 /?foo=巴 重写规则 已跳过。
    4. RewriteRule ^.*$ index.php [NC, L] 正在运行。这一切都指向 index.php --这是一个没有任何$\u GET变量的URL。这就是他们消失的原因。

    你需要把那些GET变量传递给最后一个 重写规则 .