问题
I've worked-around the solution to transform all uri to one page via ErrorDocument.
The reason behind this is to send Files AND folders (nice urls) to one page. However, I need the URI string to be sent to index.php?uri=string . Is this possible via ErrorDocument, or how do I do this?
So I need to rewrite the
http://www.something.com/games/specific-game
to
http://www.something.com/index.php?uri=/games/specific-game
Is this possible at all, if, how?
回答1:
If your server supports server-side include (SSI) then you use the following 404.shtml
as your ErrorDocument:
<html>
<header>
<meta http-equiv="Refresh" content="0; url=/index.php?uri=<!--#echo var="REQUEST_URI" -->">
</header>
</html>
EDIT: there is a simpler way: create a PHP file as your ErrorDocument and you can do anything under the sun in it! :)
EDIT2: you can access the original URI using $_SERVER['REQUEST_URI']
EDIT3: heck, if you are just redirecting to index.php
on the same host, you can just set that index.php
file as your ErrorDocument and detect if the request is redirected from 404 error by checking if $_SERVER['REDIRECT_STATUS'] == '404'
来源:https://stackoverflow.com/questions/2048888/how-can-i-get-errordocument-in-htaccess-to-output-wrong-uri-parameter