php - 自定义404 ErrorDocument路径在htaccess中不起作用

标签 php .htaccess mod-rewrite error-handling errordocument

我在.htaccess中有以下代码

ErrorDocument 400 /abc/404

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/ - [S=2]
    RewriteRule ^abc/(.*)/(.*)$ index.php?aa=$1&bb=$2 [NE,L,QSA]
    RewriteRule ^abc/(.*)$ index.php?aa=$1 [NE,L,QSA]

但每当我传递错误的网址时,我都会收到以下错误
Not Found

The requested URL /abc/[S=2] was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

如果我删除RewriteRule ^/ - [S=2]行,则出现以下错误
Not Found

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

当我尝试http://example.com/abcd/时,我希望.htaccess重定向到页面的http://example.com/abc/404
我在做什么错。请帮我。

提前致谢

最佳答案

好,用以下代码替换您的代码:

ErrorDocument 404 /abc/404

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^abc/([^/]+)/([^/]+)/?$ /index.php?aa=$1&bb=$2 [NE,L,QSA]

RewriteRule ^abc/([^/]+)/?$ /index.php?aa=$1 [NE,L,QSA]

关于php - 自定义404 ErrorDocument路径在htaccess中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17520680/

相关文章:

.htaccess - 将子域请求重定向到子目录 + https(使用 .htaccess)

javascript - 将 php 中的标记添加到 map 中

php - $_SERVER ['HTTP_REFERER' ] 安全吗?

php - 使用 .htaccess 更改 URL .php 扩展名

sql - 自定义帖子类型每年/每月存档

apache - .htaccess 从 Host 重写到没有 uri 的静态站点

regex - Apache 重写规则 - 正则表达式帮助

php - 将网站移动到登台/生产服务器的工具

php - PHP 中 skype 名称的正则表达式

apache - 通过重定向阻止目录列表?