Reputation: 21
I am trying to convert this apache .htaccess rule to something nginx can use.
This .htaccess is a part of this tutorial to make a php REST api. ( http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-23/ )
The idea of this .htaccess file is to make a REST get/post request to "task_manager/v1/register/" and it redirects you to "task_manager/v1/index.php"
.htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
I've tried one idea from stackoverflow, one from winginx, and I tried writing one myself and they all sort of flop.
Nginx config:
something I tried and failed so I commented it out.
rewrite ^/task_manager/v1/(/)$ /task_manager/v1/index.php redirect;
something I saw in stackexchange and didn't help, so I commented it out
rewrite ^task_manager/api/v1/([^/]+)/([^/]+)/?$ task_manager/api/v1/index.php?class=$1&method=$2? last;
was recommended to use winginx, didn't work. :c
location / {
if (!-e $request_filename){
rewrite ^(.*)$task_manager/v1/index.php break;
}
}
Please advise me.
Upvotes: 1
Views: 450
Reputation: 21
phew. Good thing I was only pretending to be dumb.
anyways, so yeah I was trying to make that android REST API work in nginx.
I took a look at another post ( nginx configuration for a RESTful API )
and basically I just needed to change a few things.
original:
rewrite ^/api/v1/([^/]+)/([^/]+)/?$ /apiv1.php?class=$1&method=$2? last;
Edit:
rewrite ^/task_manager/v1/([^/]+)/?$ /task_manager/v1/index.php?method=$2? last;
It seems to work for this specific tutorial. I ran into a different problem with php5-fpm but at least when I use REST Client on chrome it either gives me a 500 error (logs show something in my config isn't parsed correctly) or it will tell me "no there are no users"/"no you are not logged in" but at least this part is solved.
Upvotes: 1