How can I get ErrorDocument in .htaccess to output wrong uri parameter?

点点圈 提交于 2019-12-11 12:20:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!