我正在共享主机服务器上设置一些在本地主机上正常工作的东西,我很好奇是什么导致了这种行为。我重定向与Apache的mod_rewrite和URL到前端控制器:PHP PATH_INFO在重写后无法设置
RewriteEngine On
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
#Redirect to front controller
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
上的index.php我有调试用简单的检查设置:
if(isset($_SERVER['PATH_INFO']))
{
echo $_SERVER['PATH_INFO'];
}
else
{
echo "No Path";
}
die;
参观http://example.com/testing输出“无路径”
访问http://example.com/index.php/testing输出/测试
该重定向在我的本地主机上按照预期工作,输出“/ testing”
有谁知道这可能是什么原因造成的?有没有一种更通用的方式来做这种重定向减少从主机到主机的问题?
编辑:
分别输出$_SERVER['PATH_INFO'], $_SERVER['ORIG_PATH_INFO'], $_SERVER['PHP_SELF'], $_SERVER['REQUEST_URI']
显示:
path:
orig: /testing
self: /index.php
uri: /testing
什么处理正在做的原因? ORIG_PATH_INFO更可靠吗?此外,它似乎REQUEST_URI也是准确的,是一个更合适的变量?
是的,但是这被重定向到index.php/$ 1,它应该以http://example.com/index.php/testing作为结尾,并在/ test后面跟上文件名并且在(不存在的)查询之前串。 – 2012-02-13 22:24:33
但是该页面通过http://example.com/testing表示(重写在内部完成)。 – MasterCassim 2012-02-14 17:31:27