开发者

url rewriting for 404 page

suppose i have a file missing开发者_如何学JAVA at http://www.mydomain.com/user/10202.html i.e user.php then the server gives me 404 page default error.... than i add the following to my .htaccess file

ErrorDocument 404 /404.html

but it redirects me to http://www.mydomain.com/404.html while i want to stay on http://mydomain.com/user/10202.html and show the 404.html how can i do that...


You can use RewriteCond ant RewriteRule from mod_rewrite.

# If file doesn't exist, i display 404.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /404.html [L]


I use this two lines in my .htaccess and the link remains on the non existing (it does not redirect to error_404.html)

ErrorDocument 404 /error_404.html
RewriteRule ^error_([0-9]+).(html|php)$ error.php?error=error$1 [QSA,NC]

This works for actual files that doesn't exist but also for rewrites that are not matched correctly. In the error.php I log the error to a debugging database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜