大网数据广告活动
网站运营与故障问答

Non-existent subdirectories of index.php do not return "404 not found"

· 52CE 我爱测

My website usually correctly returns 404 not found errors if I enter names of documents or folders that do not exist. However, I have recently noticed something strange. The homepage of my website is called index.php and does not…

问题原文

原帖链接 · Run_Script · CC BY-SA 4.0

My website usually correctly returns 404 not found errors if I enter names of documents or folders that do not exist.

However, I have recently noticed something strange. The homepage of my website is called index.php and does not have any subdirectories because it is simply a file and I do not use a CMS.

But when I enter random subdirectories, such as /index.php/asdfghjk, the homepage is displayed instead of 404 not found as I would have expected. I've checked my .htaccess file and found nothing that would explain this behaviour.

The previous owner of the domain used joomla and the old site was structured in a way that all pages were subdirectories of /index.php . Could this have something to do with my problem, even though I am no longer using a CMS?

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

What you are seeing is default behaviour on Apache.

when I enter random subdirectories, such as /index.php/asdfghjk

/asdfghjk is an additional path-segment in the URL. It's not strictly a "subdirectory". (Directories and subdirectories relate to a filesystem. The URL does not necessarily map directly to the filesystem.)

When additional path segments occur after a valid file (that maps to the filesystem) in the URL, it is called additional pathname information (or path-info), and is accessible with the PHP superglobal $_SERVER['PATH_INFO'] in your PHP script.

On Apache, whether path-info is valid in the URL or not is (by default) dependent on the handler that handles the requested resource. In this case, the PHP handler allows path-info by default, so no 404, and /asdfghjk is passed to index.php to be handled by your script (some CMS use this URL pattern to create "pretty URLs" without having to resort to URL rewriting). On the other hand, the text/html handler does not allow path-info, so /index.html/asdfghjk would result in a 404 by default, unless you explicitly enable it.

To disable path-info for all requests, you can set the following at the top of the .htaccess file.

AcceptPathInfo Off

The previous owner of the domain used joomla and the old site was structured in a way that all pages were subdirectories of /index.php. Could this have something to do with my problem, even though I am no longer using a CMS?

No, this has nothing to do with Joomla. The "problem" exists regardless. Although if you are seeing many such requests in your logs then this will now doubt be because of the old URL structure. Any old URLs should be 301 redirected to the corresponding new URL (if any) in order to preserve SEO.

If they used Joomla, then they didn't need to use index.php in the URL at all (unless there was a restriction with the web host).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2020-01-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。