PHP 能够从带有斜杠的页面访问根目录中的页面

PHP able to access pages in root directory from a page with slash

我们的 PHP 网站出现问题:http://midlandssmilecentres.co.uk/

问题如下,如果你要访问,比如http://midlandssmilecentres.co.uk/feedback.php, and then put a trailing slash, it returns the index page of the root directory. From there, you can actually put any page, i.e. http://midlandssmilecentres.co.uk/feedback.php/feedback.php,它会return那个页面。我们需要停止这种行为,或者采取可行的解决方法来阻止这些页面的访问。

由于页面试图从错误的目录中获取 CSS,这给我们带来了很多重复内容和未调动页面的问题。我们已尝试删除服务器上的所有 .htaccess 文件,但这并没有解决问题。我对带有尾部斜杠的文件以及如何将文件解释为目录进行了大量研究,但找不到任何可以帮助我解决这个问题的方法。

我认为您需要设置 404 重定向,因此它不会返回该页面,而是重定向到 404 页面。

使用 .htaccess,您可以重定向所有 .php/... 个页面:

RewriteEngine on
RewriteRule ^(.+?\.php)/  [NC,L,R=301]

您还可以更改 apache 配置:

AcceptPathInfo Off

但在这种情况下将返回 404 错误
https://httpd.apache.org/docs/2.2/mod/core.html#acceptpathinfo