I'm venturing now into nginx rewrite rules so it's a fairly new topic for me.
I have in the root folder a series of pages which i use rewrite rules as follows:
server {
listen 80;
## listen [::]:80 default_server ipv6only=on;
listen 443 ssl;
root /nginx/gtt/;
index index.html index.htm index.php gttindex.php;
# Make site accessible from http://localhost/
server_name gtt.deb;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
client_max_body_size 10M;
# When access gps page just show gps
if ( $request_uri = "/gps" ) {
rewrite ^ /gps.lf.ws.vh.sprite.php break;
}
# Administration
if ( $request_uri = "/setup" ) {
rewrite ^ /admin.php break;
}
# For clientadmin show admin
if ( $request_uri = "/error" ) {
rewrite ^ /gttindex.php?WARNING=wrongcredentials break;
}
rewrite ^/cargo(.*)$/(.*)$ /clientadmin/edit_task_details_form_multi$1.php?taskid=$2 break;
rewrite ^/cargoadmin /clientadmin/admin.php last;
location / {
index index.html index.htm index.php gttindex.php;
try_files $uri $uri/ =404;
}
}
will redirect to admin.php
The problem comes when I have to rewrite in a subfolder that contains 4 php scripts:
admin.php
edit_task_details_form.php
edit_task_details_form_multi2.php
edit_task_details_form_multi3.php
It doesn't work and /cargo2/var
or /cargo3/var
(depending on which i select) are being appended to the url.
What I'd like to achieve is the following:
http://gtt.deb/clientadmin/admin.php -> http://gtt.deb/cargoadmin
http://gtt.deb/clientadmin/edit_task_details_form_multi.php?task=1 -> http://gtt.deb/cargo/1
http://gtt.deb/clientadmin/edit_task_details_form_multi2.php?task=1 -> http://gtt.deb/cargo2/1
http://gtt.deb/clientadmin/edit_task_details_form_multi3.php?task=1 -> http://gtt.deb/cargo3/1
http://somesite/cargo2/something
2. Wanted target file:/nginx/gtt/somefile.php?someparam=something
3. Target file that current setup provides:/nginx/gtt/somefile.php?someparam=1&somethingelse
. Show this concrete example, then it is possible to understand WHAT is the exact problem you have.