【发布时间】:2017-05-04 23:05:42
【问题描述】:
我想将所有“404”错误重定向到 PHP 文件。我使用来自 Wordpress 的 .htaccess 作为初始步骤。有效,但当路径是文件夹时无效,意味着末尾有一个“/”,我收到一个禁止错误。
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /includes/redir.php [L]
如果我尝试:
http://example.com/anything
按预期工作,重定向到我的 redir.php。但如果我尝试:
http://example.com/anything/
返回一个禁止错误。
我需要做什么来重定向到 redir.php 一切不存在的东西? 我需要更改 httpd.conf 吗?我需要一个“ErrorDocument 404 /includes/redir.php”行吗?
【问题讨论】:
-
澄清一下,这实际上不是 WordPress 网站?
-
不,它是一个 PHP 站点,我只是使用来自 Wordpress 站点的 .htaccess 作为起点。
-
在你上面的例子中,
/anything是一个物理目录吗?否则,您不应该收到 403 Forbidden 错误。 -
不,根文件夹中没有名为“anything”的文件夹或文件(例如)。
标签: apache .htaccess mod-rewrite http-status-code-404