In Nginx, can 301 redirect URLs be grouped in an external file that can be included in the .conf
file of the domain so that .conf
is not modified each time a 301 redirect is needed?
Example:
A .nginx file, .redirects
groups only 301 redirects:
location /test1 {
rewrite ^ http://domain.com/test2 permanent;
}
Then, .redirects
is included in the .conf
file:
include /.redirects;
Can it work? (I've tested this and it didn't work for me.)
It would work but you need to mind one thing, what context is this file going to be included to.
In your condition it's a location block, so you need to include it inside a server block, not http for example,
Also use full path not relative
server {
# bla bla
include /etc/nginx/.redirects;
}