I'm developing a PHP RESTful server for an API locally on my mac.
I've managed to enable mod_rewrite and have Overrides allowed for the site directory (~/Sites/api).
In ~/Sites/api is the .htaccess file and index.php. I'd like to rewrite all requests to http://localhost/~myusername/api/* to index.php. I need to preserve the query parameters, but that's it.
I've tried the following in the .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) index.php [QSA,NC,L]
This gives a 500:Internal Server Error.
Commenting out the FollowSymLinks line gives a 403:Forbidden error.
I can access index.php fine without the rewrites in place.
Any help you could offer would be much appreciated. I feel like weeping at the moment.
Thanks, Ross
RewriteRule ^api/(.*)$ index.php?handler=$1 [L,QSA]
Where the handler is what is passed to your index.php script. For instance, a request for
http://localhost/~myusername/api/getUser/myusername
would be rewritten to
http://localhost/~myusername/api/index.php?handler=getUser/myusername
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With