当我在.php网址后加上斜杠(/)时会发生什么? [英] What happens when i put a slash (/) after a .php url?

查看:123
本文介绍了当我在.php网址后加上斜杠(/)时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题,但是在任何地方都找不到答案

I have a simple question, but could not find the answer anywhere

说我有一个网站"mysite.com". 我可以通过输入"mysite.com"或"mysite.com/index.php"来访问索引页面. 效果很好...但是,当我尝试转到"mysite.com/index.php/"时,页面加载,但不正确. 到底是怎么回事?我认为它应该返回404错误,因为index.php将被视为一个(不存在的)目录(即,我认为它将尝试查找"mysite.com/index.php/index.php"). 显然不是这样.有人可以告诉我发生了什么吗? 当您在斜杠后面加上任何内容时也是如此,即"mysite.com/index.php/hello"

say I have a site "mysite.com". I can access the index page by either typing "mysite.com" or "mysite.com/index.php". This works fine... however, when i try to go to "mysite.com/index.php/" the page loads, but not correctly. what is exactly happening? I would think it should return a 404 error, since index.php would be treated as a (non existing) directory (i.e. i would think it would try to find "mysite.com/index.php/index.php"). This clearly isn't the case. Can someone please tell me what exactly is happening? This is also true when you put anything after the slash, i.e. "mysite.com/index.php/hello"

谢谢.

推荐答案

这是由于您的Apache环境变量PATH_INFO所致.

This is due to your Apache environmental variable called PATH_INFO.

PATH_INFO

实际上,PATH_INFO与服务PHP页面的Apache Web服务器有关,而不是与PHP说的有关.

Actually, PATH_INFO is related to the Apache Web Server serving PHP pages and not PHP per-say.

PATH_INFO是Apache在打开AcceptPathInfo指令时设置的环境变量.它将包含尾随路径名信息,该路径名信息将跟随或拒绝实际文件名(或现有目录中不存在的文件).然后将环境变量传递给负责呈现页面的Apache/CGI模块.

PATH_INFO is an environment variable set by Apache when the AcceptPathInfo directive is turned on. It will contain trailing pathname information that follows an actual filename (or non-existent file in an existing directory) will be accepted or rejected. Environment variables are then passed on to the Apache/CGI module in charge of rendering the page.

可以在PHP中使用$ _SERVER ['PATH_INFO']访问该变量.

The variable is accessible in PHP using $_SERVER['PATH_INFO'].

例如,假设位置/test/指向一个仅包含单个文件here.html的目录.然后,对/test/here.html/more和/test/nothere.html/more的请求都将/more作为PATH_INFO收集.

For example, assume the location /test/ points to a directory that contains only the single file here.html. Then requests for /test/here.html/more and /test/nothere.html/more both collect /more as PATH_INFO.

此答案摘自安德鲁·摩尔(Andrew Moore) 链接到原始答案

This answer is copied from Andrew Moore Link to original answer

这篇关于当我在.php网址后加上斜杠(/)时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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