# Too many redirects

**URL:** <https://www.ruby-forum.com/t/too-many-redirects/212558>\
**Category:** NGINX\
**Created:** [October 6, 2011, 7:27am UTC](https://www.ruby-forum.com/t/too-many-redirects/212558 "2011-10-06T07:27:22Z")\
**Posts on this page:** 2\
**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:** [October 6, 2011, 7:27am UTC](https://www.ruby-forum.com/t/too-many-redirects/212558/1 "2011-10-06T07:27:22Z")

</div>

I’m following the wiki’s guidelines with:

server {  
server\_name [mike.example.com](http://mike.example.com);  
rewrite ^ http://www.example.com$request\_uri? permanent;  
}

I’m getting a “this page has too many redirects error”. So I tried:

location = [example.com](http://example.com) { rewrite [example.com](http://example.com) [www.example.com](http://www.example.com) permanent;  
}

This worked after I had gone to [www.example.com](http://www.example.com) but if I clear the cache  
and  
first go to [example.com](http://example.com) (like a first-time user) I get a “DNS lookup  
failed.”

Any suggestions, thanks.

–  
View this message in context:  
[http://nginx.2469901.n2.nabble.com/too-many-redirects-tp6864778p6864778.html](http://nginx.2469901.n2.nabble.com/too-many-redirects-tp6864778p6864778.html)  
Sent from the nginx mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![seminal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e79b87/32.png) [@seminal](https://www.ruby-forum.com/u/seminal)\
**Post date:** [October 6, 2011, 8:35am UTC](https://www.ruby-forum.com/t/too-many-redirects/212558/2 "2011-10-06T08:35:15Z")

</div>

On Wed, Oct 05, 2011 at 08:32:52PM -0700, seminal wrote:

> I’m following the wiki’s guidelines with:
> 
> server {  
> server\_name [mike.example.com](http://mike.example.com);  
> rewrite ^ http://www.example.com$request\_uri? permanent;  
> }
> 
> I’m getting a “this page has too many redirects error”. So I tried:
> 
> location = [example.com](http://example.com) { rewrite [example.com](http://example.com) [www.example.com](http://www.example.com) permanent; }

This location has no sense from nginx point of view.

> This worked after I had gone to [www.example.com](http://www.example.com) but if I clear the cache and  
> first go to [example.com](http://example.com) (like a first-time user) I get a “DNS lookup  
> failed.”
> 
> Any suggestions, thanks.

server {  
server\_name [example.com](http://example.com);  
rewrite ^ http://www.example.com$request\_uri? permanent;  
}

server {  
server\_name [www.example.com](http://www.example.com);  
…  
}

–  
Igor S.
