I want that every call with
http://localhost/api/
(as root folder) for example http://localhost/api/get/users
actually is http://localhost/api/index.php?handler=get/users
.
http://localhost/api/get/user/87
should be http://localhost/api/index.php?handler=get/user/87
where in index.php I would catch $_GET variable handler and handle it in proper way.
If I have this kind of rewrite rules it works only for one
RewriteRule ^([^/\.]+)/?$ index.php?handler=$1 [QSA,L]
two
RewriteRule ^([^/\.]+)/?$ index.php?handler=$1 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?handler=$1&handler2=$2 [QSA,L]
three slashes and so on...
RewriteRule ^([^/\.]+)/?$ index.php?handler=$1 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?handler=$1&handler2=$2 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?handler=$1&handler2=$2&handler3=$3 [QSA,L]
So for the first case http://localhost/api/a
would work, but http://localhost/api/a/b
would cause a Not Found error.
EDIT: Should this be fine?
RewriteRule ^(.*)$ index.php?handler=$1 [L,QSA]
Your (own) answer should be fine, just keep in mind that it will redirect all incoming URLs to
index.php
. I.e. if you have static files, for example/js/jquery.js
then it will be changed toindex.php?handler=/js/jquery.js
.If you want to avoid problems try something like:
Two hints:
Please try to use the
RewriteLog
directive: it helps you to track down such problems:My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)