【发布时间】:2018-09-15 14:39:00
【问题描述】:
我正在开发一个原始的 PHP Web 应用程序。但是,当我在 url 之后使用无效词(仅用于检查)时,我遇到了问题。
当前 htaccess 代码:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
ErrorDocument 404 https://example.com/404
Options -Indexes
例如:
我需要https://example.com/profile(没有扩展名)。现在正在使用以下 htaccess 代码。当我点击https://example.com/profile/lllflfl(lllflfl 是无效词,仅用于检查 404 错误)时,它会转到 404 错误页面。这也很好。但是,当我点击https://example.com/profile.php/lllflfl 时,我的网站仍然显示当前页面(当前页面表示https://example.com/profile 此页面)。我认为这需要重定向 404 页面。你的想法是什么?
谢谢。
【问题讨论】:
-
/file.php/foo/bar指向/file.php,因为/foo/bar(文件名后的跟踪路径)是 PATH INFO 的一部分。默认情况下,它在 apache 上启用。您可以在 htacessAcceptPathInfo Off中使用以下行禁用它。
标签: php .htaccess http-status-code-404