Rerouting all php requests through index.php
Here's what I use (and have used for ages):
<IfModule mod_rewrite.c>
# Redirect /index.php to / (optional, but recommended I guess)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php
RewriteRule ^index.php/?(.*)$ $1 [R=301,L]
# Run everything else but real files through index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1?%{QUERY_STRING} [L]
</IfModule>
As the comments suggest it will route every request that isn't an actual file to index.php
Use:
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php|public|css|js|robots\.txt) RewriteRule ^(.*)$ index.php/params=$1 [L,QSA] ErrorDocument 404 /index.php
Url sample: www.site.com/friend/josh/03-13-2012
So the $params var value:
friend/josh/03-13-2012
Only need explode() "/" so u get array with params:
array(
0 => friend
1 => josh
2 => 03-13-2012
)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !index\.php$
RewriteRule .*\.php$ index.php?q=%{REQUEST_URI} [L]
Will catch all requests ending in .php that don't point to a file ending in index.php and redirect them to index.php in the get parameter q
To redirect all non-existent requests to /index.php , You can also use ErrorDocument and FallbackResource directives .
Try one of the following examples :
ErrorDocument 404 /index.php
FallbackResource /index.php
These directives are part of apache core modules and you dont need to enable mod-rewrite to use them.
If you are looking for a way to redirect all requests (including real files/dirs) then try the following Redirect
RedirectMatch ^/(?!index\.php).+)$ /index.php