Sammy
Sammy

Reputation: 23

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

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?

Upvotes: 2

Views: 1432

Answers (1)

renard
renard

Reputation: 1468

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]

Upvotes: 3

Related Questions