I need to setup about 5-6k redirects on a domain (for a site migration), and I'm new to nginx. I have some test redirects working in the main .conf file for the domain. But I don't want to have 5k+ rewrites in the main .conf file so I have been told that I can include a external file in the .conf to keep it clean, so my main .conf like this
server {
listen.....etc
etc
rewrite ^oldurl newurl permanent;
rewrite ^oldurl newurl permanent;
include /etc/nginx/conf.d/redirects.conf;
location ....etc
etc
}
Then in the redirects.conf I just have
rewrite ^oldurl newurl permanent;
But when I try to restart nginx I get the error:
"rewrite" directive is not allowed here in /etc/nginx/conf.d/redirects.conf:1
Thanks
OK, issue was I was calling the extenal file redirects.conf, since every file ending in .conf is considered a site configuration file.
I changed it to sitename.redirects and now it works fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With