简体   繁体   English

Nginx重写-上次被忽略吗?

[英]Nginx Rewrite - Last Ignored?

In Apache, this logic works fine - and according to documentation, with Nginx too. 在Apache中,此逻辑可以正常工作-根据文档,Nginx也可以。

location = /login/ {    rewrite ^(.*)$ /login.php last; }
rewrite ^/([^/]*)/$ /page.php?c=$1 last;

Ideally, domain.com/login/ would direct to login.php 理想情况下,domain.com / login /可以直接登录login.php

Anything else would direct to page.php, and pass along the details. 其他任何操作都将直接指向page.php,并传递详细信息。 However, instead - all requests are directed to page.php 但是,相反-所有请求都定向到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 . Nginx严格执行指令,并且在尝试匹配location之前先进行“服务器级” rewrite

You should avoid “server-level” rewrite s. 您应该避免“服务器级” rewrite 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$ {
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM