Apache mod_rewrite

I am developing a RESTful API and am trying to configure .htaccess with a rewrite condition. Hopefully, there’s a mod_rewrite expert out there.

If I wanted to retrieve a list of users I’d like to be able to issue the URL https://api.mysite.com/app1/users/list. The actual URL (that works) would be https://api.mysite.com/app1/index.php/users/list.

https://api.mysite.com/app1/users/list = https://api.mysite.com/app1/index.php/users/list

Such a simple request with such a confusing answer?

This will need testing as it’s off the cuff, but something like this should work:

RewriteCond %{REQUEST_URI} !index.php [NC] RewriteRule ^/app1/?(.+)$ /app1/index.php/$1 [L,QSA,NE,R]

I’m getting a “File does not exist: /var/www/api/app1/users”

I still get the correct output when I use api.mysite.com/app1/index.php/users/list and the rewritten URL is api.mysite.com/app1/users/list but I end up with a 404 Not Found.

Like I said, it needed testing. You can check the Apache error log for clues (may have to increase the logging level).

Also, I don’t understand the following

I thought this is the URL you’re entering, which is supposed to be rewritten. What do you mean here?


You are correct, when I browse http://api.mysite.com/app1/users/list, I see the following in the Apache error log.

[Wed Oct 16 01:07:46 2013] [error] [client] File does not exist: /var/www/api/app1/hello

root@devweb:/var/www/api/app1# ls -l
total 8
-rw-r–r-- 1 root root 178 Oct 7 23:45 index.php
drwxr-xr-x 6 root root 4096 Sep 29 13:46 Slim

I appreciate your comments. RegEx is a beast I can’t even begin to understand.