【发布时间】:2012-02-21 03:33:23
【问题描述】:
我正在尝试编写一个 .htaccess 文件来定向并发送带有错误代码的索引。例如 index.php?error404 或 index.php?error501。
我可以使用下面的代码在根目录中引导错误。
ErrorDocument 404 index.php?error=404
ErrorDocument 501 index.php?error=501
例如http://www.domain.com/file_does_not_exist.php 并且这有效。 结果http://www.domain.com/index.php?error=404
问题是从子目录捕获并发送到 index.php 错误。
例如http://www.domain.com/directory_does_not_exist 或 http://www.domain.com/directory_and/file_does_not_exist.php.
结果是http://www.domain.com/directory_does_not_exist/index.php?error=404,因此 index.php 的 CSS 损坏了。
我尝试了下面的代码但没有成功。我正在尝试通过重写 URL 来重定向回 index.php。
RewriteCond $1 !^err[45][0-9][0-9]$
RewriteRule ^\/.\/\.php$ /index.php?s=$1 [R]
AND
RewriteCond $1 !^err[45][0-9][0-9]$
RewriteRule ^([/]?*)\.php$ /index.php?s=$1 [QSA,L]
任何帮助将不胜感激。
【问题讨论】: