LittleLebowski
LittleLebowski

Reputation: 7941

Regex to block url in nginx

I want to block access to urls that have excess characters at its end.

E.g. I want nginx to block requests to https://www.example.com/url-pattern/amp/extra-chars/more-extra

but want it to allow https://www.example.com/url-pattern/amp or https://www.example.com/url-pattern/amp/

Will this work?

location .*\/amp\/. {
   deny all
}

Please guide.

Upvotes: 4

Views: 9551

Answers (1)

LittleLebowski
LittleLebowski

Reputation: 7941

Solved it myself. If anyone is looking for the same solution

location ~* /amp/. {
 deny all;
}

Upvotes: 13

Related Questions