Question on 301 redirect

Hi,

Is there any way I can 301 redirect a lot of (>10k) old urls to new urls
in nginx conf?
Writing 10k lines of rewrite rules seems to be not efficient as those
rules will get checked for every single request.
I’m thinking of some data structure like dict in python which can have a
quick look up of the key and then do the redirect of the value. The
question is how can I do that in nginx?

Thanks a lot!

Posted at Nginx Forum:

Hello!

On Thu, Aug 04, 2011 at 11:52:06PM -0400, zflairz wrote:

Is there any way I can 301 redirect a lot of (>10k) old urls to new urls
in nginx conf?
Writing 10k lines of rewrite rules seems to be not efficient as those
rules will get checked for every single request.
I’m thinking of some data structure like dict in python which can have a
quick look up of the key and then do the redirect of the value. The
question is how can I do that in nginx?

http://wiki.nginx.org/HttpMapModule

Maxim D.

Is this HttpMapModule an O(1) (not O(N)) operation when doing the
lookup? This is because I have tens of thousands of urls to be mapped
(can’t derive a regular expression out of them), so an O(1) is perf-wise
required. Thank you!

Posted at Nginx Forum:

Hello!

On Fri, Aug 05, 2011 at 03:53:24AM -0400, zflairz wrote:

Is this HttpMapModule an O(1) (not O(N)) operation when doing the
lookup? This is because I have tens of thousands of urls to be mapped
(can’t derive a regular expression out of them), so an O(1) is perf-wise
required. Thank you!

Yes, map module uses hash table and it’s O(1) with static strings
(obviously enough it’s still O(N) with regular expressions as
supported in 0.9.6+).

Maxim D.