Rewrite rule to simplify codeigniter code for REST api
I am writing a REST api in codeigniter using https://github.com/chriskacerguis/codeigniter-restserver REST controller library. I wrote my controller inside application/controllers/api/v1
and overrides the Router class to allow multiple sub-folders inside controllers.
Now I want to access services as http://api.domain.com/v1/user/11 instead of http://api.domain.com/api/v1/user/11
I have tried following the htaccess rule
RewriteCond %{HTTP_HOST} ^api\.domain\.com$
RewriteCond %{REQUEST_URI} !index.php/
RewriteRule ^(.*)/?$ /index.php/api/$1 [QSA,L]
But it doesn't seem to work because the REQUEST_URI in the $ _SERVER global variable has a value v1/user/11
instead api/v1/user/11
, so codeigniter can't find the controller.
Is there a way to achieve this requirement other than setting the REQUEST_URI change in index.php?
I do NOT want to do a permanent redirect.
Any help is greatly appreciated.
source to share