Apache/Mod Rewrite: Route everything to index.php?

走远了吗. 提交于 2019-12-20 02:57:26

问题


I'm writing a front-controller that will handle page requests, by parsing

$_SERVER['REQUEST_URI'].

I would like to get all requests routed to /index.php

Some examples as follows:

example.com/page2?foo=bar
example.com/page2/?foo=bar
example.com/page/action/123/
example.com/page/action/123

What is the regexp rule that i have to write in .htaccess ?

And do I need an extra rule so that example.com/images/ directory would work as 'normal' directory?


回答1:


You could try something like this :

RewriteCond %{REQUEST_URI} !^/dir_under_rootdocument/index\.php
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|js|css)$
RewriteRule (.*) dir_under_rootdocument/index.php/$1 [L,QSA]


来源:https://stackoverflow.com/questions/11243709/apache-mod-rewrite-route-everything-to-index-php

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