php - 重定向到主页而不是 404 错误页面!

标签 php .htaccess redirect http-status-code-404

我正在使用 PHP。我有一个如下所示的 .htaccess 文件,它重定向到主页而不是 404 错误页面:/这里可能是什么问题?感谢帮助!非常感谢!

ErrorDocument 404 /new/err404.html
RewriteEngine On
RewriteBase /new/

RewriteRule ^login.html$ index.php?s=login&a=loginDo [QSA,L]
RewriteRule ^logout.html$ index.php?s=login&a=logoutDo [QSA,L]
RewriteRule ^([^/]*).html$ index.php?s=$1 [QSA,L]
RewriteRule ^members/([^/]*)$ index.php?s=profile&username=$1 [QSA,L]
RewriteRule ^([^/]*)/$ index.php?s=listing&search[cityString]=$1 [QSA,L]
RewriteRule ^([^/]*)/([^/]*)/$ index.php?s=listing&search[neighborhoodString]=$2 [QSA,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*).html$ index.php?s=details&seo_friendly=$3 [QSA,L]

最佳答案

没有路径前缀 /new/ 的 URL 路径或错误文档 /new/err404.html 只是 err404.html。这将与您的第三条规则相匹配。

您可以扩展该规则并排除此类错误文档:

RewriteCond $1 !^err[45][0-9][0-9]$
RewriteRule ^([^/]*)\.html$ index.php?s=$1 [QSA,L]

关于php - 重定向到主页而不是 404 错误页面!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1565628/

相关文章:

php - 在 PHP 中创建一次性使用的安全 token 的最佳方法是什么?

php - Foreach不插入MySQL的字段

.htaccess - 如何在 htaccess 中将 3 行重写为 1 行

php - Slim 框架 - 无法用点解释路由

html - 拒绝访问 css/和 js/文件夹或使用 htaccess 重定向/重写到 index.html

http - 是否可以透明地委托(delegate) HTTP 请求?

php - 在 php 中使用正则表达式删除 span 标签

php - Laravel 5.3 创建模型返回 "Field doesn' t 有默认值”

php - 正确重定向访问者(PHP 和 Regex)

Apache 虚拟主机重定向不起作用