# D

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

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [August 5, 2011, 5:51am UTC](https://www.ruby-forum.com/t/d/210332/1 "2011-08-05T05:51:11Z")

</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:

> **[d](https://forum.nginx.org/read.php?2,213410,213410#msg-213410)**
>
> 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, 6:54am UTC](https://www.ruby-forum.com/t/d/210332/2 "2011-08-05T06:54:40Z")

</div>

Perhaps you can just pass it using fcgi to a lookup script that performs  
the  
redirect.  
On Aug 4, 2011 11:51 PM, “zflairz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks a lot!
> 
> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,213410,213410#msg-213410](http://forum.nginx.org/read.php?2,213410,213410#msg-213410)

---

<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, 1:59pm UTC](https://www.ruby-forum.com/t/d/210332/3 "2011-08-05T13:59:55Z")

</div>

Use a map :

map $uri $new\_url {  
defau;t 0;  
/old/url /new/url  
/1 /new/1;  
}

then in your server config:

if ($new\_url) {  
rewrite ^ $new\_url permanent;  
}

---

<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, 3:09pm UTC](https://www.ruby-forum.com/t/d/210332/4 "2011-08-05T15:09:42Z")

</div>

Thank you. I’m doing exactly the same (as also suggested by others in  
another thread) 🙂

Posted at Nginx Forum:

> **[Re: RE: d](https://forum.nginx.org/read.php?2,213410,213429#msg-213429)**
>
> 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...
