Search code examples
nginxnginx-config

How to block any url contain word 'author' in nginx?


I want block any URL contain word 'author' in nginx.

Like:

exmaple.com/author/exmple....
exmaple.com/?author=2/exmple....
exmaple.com/?author=4
exmaple.com/blog/?author=1
exmaple.com/blog/author/wellcome
.
.
.

I use below code then restart nginx but not work for all URL.

location ~ author{
 deny all;
}

How can I do?


Solution

  • I use 2 rule :

    for below url:

    www.exmaple.com/author/exmple....
    www.exmaple.com/blog/author/wellcome
    

    I use:

    location ~ author{
    return 403;
    }
    

    And for below url :

    www.exmaple.com/?author=2/exmple....
    www.exmaple.com/?author=4
    www.exmaple.com/blog/?author=1
    

    I use

      if ($request_uri  ~* author ) {
            return 403;
        }