0

We have a site built with WordPress with nginx web server. I want to do multiple redirection in one line of code in our nginx file.

The code below runs smoothly:

location /wp-links-opml.php {
  return 301 https://$host/page-not-found;
}

What I want to happen is redirect multiple files in just one config:

location /wp-links-opml.php /wp-config-sample.php /wp-load.php {
  return 301 https://$host/page-not-found;
}

All of the files above belong in root directory but nginx prompts with nginx exited with code 1

Do you know how can I properly redirect multiple files in 1 config?

Note: I tried this How can I have same rule for two locations in NGINX config? but in my case I am working with php files and not locations

Any help is greatly appreciated. Thanks.

redshot
  • 2,930
  • 3
  • 31
  • 68

1 Answers1

2

That's how you could use one location for multiple files:

    location ~ ^/(wp-links-opml.php|wp-config-sample.php|wp-load.php)$ {
        return 301 https://$host/page-not-found;
    }
Richard Smith
  • 45,711
  • 6
  • 82
  • 81
metallic
  • 361
  • 2
  • 4
  • thank you for this. what i also did with your code is put the new config on top of the default `nginx` php config. i think it has an effect in terms of priority – redshot Jul 23 '19 at 12:45