5

I'm planning to do a lot of redirects in nginx with mapping files like in the example below, but just discovered that I have to redirect about 57,000 URLs. Is putting them in config files like this the best way to do it, or is there a better way?

map $request_uri $redirect_uri {
    /old-path-1     /new-path-1;
    /old-path-2     /new-path-2;
    /old-path-3     /new-path-3;
}

The redirects are mostly for the search engines. After they re-index the site, I think there won't be a huge number of hits on the old URLs. I'm mainly concerned about potential problems from creating a configuration file that has that many lines in it.

Update: it worked fine.

6
  • Stating the version you're using might help.
    – gxx
    Oct 20, 2017 at 20:58
  • I'm going to build a new server, so I could use any version. The current server is running 1.10 though.
    – R891
    Oct 20, 2017 at 21:05
  • Create one with 10 times your desired entries and compare startup time, latency & memory. Will the list grow in the future?
    – anx
    Oct 20, 2017 at 22:48
  • They are just the URLs from a previous version of the site. The list won't grow significantly in the future, unless there is another rebuild, which would be years away.
    – R891
    Oct 20, 2017 at 22:56
  • 1
    @AhmadMobaraki It worked fine with a few thousand visitors per day on a small server.
    – R891
    Sep 23 at 0:27

1 Answer 1

2

That should work fine. Note you can also use include directive for your maps so your config files would look pretty

BTW here are a couple of alternatives:

  1. You could also use proxy_cache and generate this URLs via PHP/Python/whatever else is behind nginx if it's more convenient for some reason. Note it's much slower
  2. Use exact matches, check out this thread

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.