N
N
Nikita Fedorchuk2019-06-11 12:36:37
Nginx
Nikita Fedorchuk, 2019-06-11 12:36:37

How to exclude a directory from their rewrite (nginx)?

Good day. There is the next rewrite, everything without a slash except POST.

if ($request_method != "POST"){
    rewrite ^/(.*)\/$ /$1 permanent;
}

location  / {
    try_files $uri $uri/ /index.php?$args;
    allow 127.0.0.1;
    allow 192.168.0.11
    deny all;
    error_page 403 = @403;
}
location @403 {
keepalive_timeout 0;
return 503;
}

Guys tell me how to exclude from rewrite location /admin/ ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-06-11
@nikita0101

Add (?!admin/).
rewrite ^/(?!admin/)(.*)/$ /$1 permanent;

K
ky0, 2019-06-11
@ky0

It would be more correct to add a separate location that would be executed before the default /.
https://nginx.org/ru/docs/http/request_processing.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question