简体   繁体   中英

nginx Rewrite Rules to Re-write Every Match Of a Certain Regex Except

I'm writing rewrite rules in nginx.

I want to rewrite every URI that matches /A/B[anything] to /X/ except /A/B/C[/] .

How do I do this?

What I've tried:

if ($request_uri ~ ^/A/B/C/?) {
    break;
}
rewrite ^/A/B   /X/   permanent;

This rewrites /A/B to /X/ , but /A/B[anything] doesn't get redirected, nor does /A/B/C/ stay at /A/B/C/ .

rewrite ^/A/B/?$   /X/   permanent;

应该做

I figured out the issue.

I needed to make the rewrite line

rewrite ^/A/B(.*)?   /X/   permanent;

The (.*)? means " and optionally match anything any amount of times."

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.

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