# Question on 301 redirect

**URL:** <https://www.ruby-forum.com/t/question-on-301-redirect/210333>\
**Category:** NGINX\
**Created:** [August 5, 2011, 5:52am UTC](https://www.ruby-forum.com/t/question-on-301-redirect/210333 "2011-08-05T05:52:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 5, 2011, 5:52am UTC](https://www.ruby-forum.com/t/question-on-301-redirect/210333/1 "2011-08-05T05:52:25Z")

</div>

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:

> **[Question on 301 redirect](https://forum.nginx.org/read.php?2,213411,213411#msg-213411)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![zflairz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/dc4da7/32.png) [@zflairz](https://www.ruby-forum.com/u/zflairz)\
**Post date:** [August 5, 2011, 8:38am UTC](https://www.ruby-forum.com/t/question-on-301-redirect/210333/2 "2011-08-05T08:38:23Z")

</div>

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?

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Maxim D.

---

<div class="post-metadata">

**Author:** ![zflairz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/dc4da7/32.png) [@zflairz](https://www.ruby-forum.com/u/zflairz)\
**Post date:** [August 5, 2011, 9:53am UTC](https://www.ruby-forum.com/t/question-on-301-redirect/210333/3 "2011-08-05T09:53:49Z")

</div>

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:

> **[Re: Question on 301 redirect](https://forum.nginx.org/read.php?2,213411,213420#msg-213420)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![zflairz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/dc4da7/32.png) [@zflairz](https://www.ruby-forum.com/u/zflairz)\
**Post date:** [August 5, 2011, 10:54am UTC](https://www.ruby-forum.com/t/question-on-301-redirect/210333/4 "2011-08-05T10:54:23Z")

</div>

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.
