In Apache, this logic works fine - and according to documentation, with Nginx too.
location = /login/ { rewrite ^(.*)$ /login.php last; }
rewrite ^/([^/]*)/$ /page.php?c=$1 last;
Ideally, domain.com/login/ would direct to login.php
Anything else would direct to page.php, and pass along the details. However, instead - all requests are directed to page.php
Is something missing? :)
I guess, you have wrong assumption that order of directives matters, but actually it does not. Nginx has strict order of directives execution and “server-level” rewrite
works before it tries to match location
.
You should avoid “server-level” rewrite
s. In this case I would write:
location / {
rewrite ^/([^/]*)/$ /page.php?c=$1;
}
location = /login/ {
rewrite ^ /login.php;
}
# I guess you have something like this too
location ~ \.php$ {
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.