问题
I have the following code which works great:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?mode=$1 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?mode=$1&productContent=$2 [QSA]
My problem is when I go to a page that doesn't exist on my site ie. mysite.com/books I get the following warning error: failed to open stream: No such file or directory. Is there a way to avoid this error and have it go to "404 Page Not Found" instead?
回答1:
You can't handle that with Apache's mod_rewrite, it's a script error and has to be taken care of by the code, php in your case.
来源:https://stackoverflow.com/questions/15396454/mod-rewrites-wont-go-to-404-page-not-found-for-non-existing-pages