我在.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
这是一个页面
提前致谢
答案 0 :(得分:1)
好用这段代码替换你的代码:
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]