我在.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/