【发布时间】:2011-05-04 14:19:01
【问题描述】:
我目前正在处理一个项目,其中我的 Apache 文档根目录与我的 index.php 所在的公共目录不同。奇怪的是,由于这个设置,我的 $_GET superglobal 似乎被清空了。
目录结构:
- /Documentroot
- /Documentroot/.htaccess
- /public/.htaccess
- /public/index.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]
一些观察:
- 删除主 .htaccess 并在 documentoot 中放置一个额外的 index.php 时,我的 $_GET 变量显示正常
- 在 /public/index.php 文件中转储 $_GET 时,它是空的
- 像 /?foo=bar 这样调用 index.php 时,$_GET 为空
- 当像 /index.php?foo=bar 那样调用 index.php 时,会填充 $_GET
什么可能导致 $_GET 变量被清空?感谢任何帮助。
编辑:事情变得非常陌生:
当我保留两个 .htaccess 文件完整并在 documentroot 中放置一个 index.php(或任何 index.*)文件(无论是什么内容)时, /public 目录中的 index.php 文件将被解析并且 $_GET 变量已正确填充。
【问题讨论】:
-
可能不是问题,但您确定文档根目录中没有
index.htm或其他类似文件吗?尝试将DirectoryIndex index.php添加到您的.htaccess。 -
感谢您的评论,但我确信这不是问题。
标签: php apache .htaccess mod-rewrite