为什么$ _ SERVER ['PATH_TRANSLATED']重演? [英] Why is $_SERVER['PATH_TRANSLATED'] repeating itself?

查看:1002
本文介绍了为什么$ _ SERVER ['PATH_TRANSLATED']重演?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个MVC框架时,我注意到了$ _ SERVER ['PATH_TRANSLATED']变量是这样做的:

I'm trying to create a MVC framework when I noticed the $_SERVER['PATH_TRANSLATED'] variable is doing this:

[PATH_INFO] => /测试/ TEST2 / TEST3

   [PATH_TRANSLATED] =>重定向:/index.php/test/test2/test3/test2/test3

[PATH_INFO] => /test/test2/test3
[PATH_TRANSLATED] => redirect:/index.php/test/test2/test3/test2/test3

这是当我通过访问http PHP文件://domain.tld/test/test2 / TEST3

请注意,它是如何地重复/测试/​​

This is when I'm accessing the PHP file by http://domain.tld/test/test2/test3
Notice how it is repeating after /test/

这是我改写的.htaccess:

This is my .htaccess for rewriting:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

任何想法?我试图改变周围的重写规则规则,但什么都没有改变。该变量是不是我试图但是做什么,我想知道为什么发生这种情况,如果我有一些错误配置的重要。

Any ideas? I tried changing the RewriteRule rule around but nothing changed. The variable isn't that important for what I am trying to do however, I am wondering why this is happening and if I have something misconfigured.

服务器信息:

阿帕奇/ 2.2.3

PHP 5.3.1

Server Info:
Apache/2.2.3
PHP 5.3.1

编辑:这个变量不会重演Lighttpd的计划,因为它报道:

This variable doesn't repeat itself under Lighttpd, as it reports:

[PATH_INFO] => /测试/ TEST2 / TEST3

  [PATH_TRANSLATED] => /家庭/克莱默/的public_html /测试/ TEST2 / TEST3

[PATH_INFO] => /test/test2/test3
[PATH_TRANSLATED] => /home/kramer/public_html/test/test2/test3

所以我假定它有事情做与Apache。我也试过FastCGI的Apache下,它产生的相同的重复的结果。

So I am assuming it has something to do with Apache. I also tried FastCGI under Apache and it produced the same repeating result.

推荐答案

如果您使用的是的mod_rewrite ,然后读 PATH_TRANSLATED 值将在脚本没有用的,因为它会指向一个不存在的文件或路径。你应该使用 PATH_INFO 你的的index.php 来知道被用户请求的URI。

If you are using mod_rewrite, then reading the PATH_TRANSLATED value will have no use in your script, since it will point to a non-existence file or path. You should use PATH_INFO in your index.php to know the URI that was requested by user.

有关一个例子,你可以看看 codeIgniter的 Router类。 codeIgniter可以用几种方式来获取URI参数: PATH_INFO QUERY_STRING REQUEST_URI ORIG_PATH_INFO

For an example, you can take a look at CodeIgniter's Router class. CodeIgniter can use several ways to get the URI parameters: PATH_INFO, QUERY_STRING, REQUEST_URI, and ORIG_PATH_INFO.

如果你仍然好奇与你的Apache的奇怪行为,也许挖掘访问日志会透露一些线索的罪魁祸首。但是,如果你不使用这个变量,只是忘了。它服务于不同的目的,和你的MVC不会去使用它。

If you are still curious with the strange behavior of your Apache, maybe digging into the access log will reveal some clue to the culprit. However, if you are not using this variable, just forget it. It serves a different purpose, and your MVC will not be going to use it.

这篇关于为什么$ _ SERVER ['PATH_TRANSLATED']重演?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆