# Trying to use 301 redirect, but the server does a 302

**URL:** <https://www.ruby-forum.com/t/trying-to-use-301-redirect-but-the-server-does-a-302/172750>\
**Category:** Rails\
**Created:** [July 27, 2009, 1:44pm UTC](https://www.ruby-forum.com/t/trying-to-use-301-redirect-but-the-server-does-a-302/172750 "2009-07-27T13:44:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yannimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/7993a0/32.png) [@yannimac](https://www.ruby-forum.com/u/yannimac)\
**Post date:** [July 27, 2009, 1:44pm UTC](https://www.ruby-forum.com/t/trying-to-use-301-redirect-but-the-server-does-a-302/172750/1 "2009-07-27T13:44:24Z")

</div>

I am using the following code to do a 301 redirect in my controller:

headers[“Status”] = “301 Moved Permanently”  
redirect\_to “/somepage” and return

I am using nginx in front of mongrel cluster.

When I tested the URL at [http://checkmyheaders.com/](http://checkmyheaders.com/), it returns the  
following info:

HTTP/1.1 302 Moved Temporarily  
Server: nginx/0.7.59  
Date: Mon, 27 Jul 2009 11:42:17 GMT  
Content-Type: text/html; charset=utf-8  
Connection: keep-alive  
Set-Cookie:  
Status: 302  
…

What gives?? Is mongrel or nginx changing this to a 302 somewhere along  
the way??

---

<div class="post-metadata">

**Author:** ![yannimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/7993a0/32.png) [@yannimac](https://www.ruby-forum.com/u/yannimac)\
**Post date:** [July 27, 2009, 2:26pm UTC](https://www.ruby-forum.com/t/trying-to-use-301-redirect-but-the-server-does-a-302/172750/2 "2009-07-27T14:26:41Z")

</div>

Hi Yanni,

have you tried this:

redirect\_to “/somepage”, :status=\>:moved\_permanently

Read  
[ActionController::Base](http://api.rubyonrails.org/classes/ActionController/Base.html#M000662).

Regards  
Nicolai

---

<div class="post-metadata">

**Author:** ![yannimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/7993a0/32.png) [@yannimac](https://www.ruby-forum.com/u/yannimac)\
**Post date:** [July 27, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/trying-to-use-301-redirect-but-the-server-does-a-302/172750/3 "2009-07-27T14:28:52Z")

</div>

That worked great! Thanks! I guess the old way does not work with the  
latest version of rails.

Nicolai Reuschling wrote:

> Hi Yanni,
> 
> have you tried this:
> 
> redirect\_to “/somepage”, :status=\>:moved\_permanently
> 
> Read  
> [ActionController::Base](http://api.rubyonrails.org/classes/ActionController/Base.html#M000662).
> 
> Regards  
> Nicolai

---

<div class="post-metadata">

**Author:** ![yannimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/7993a0/32.png) [@yannimac](https://www.ruby-forum.com/u/yannimac)\
**Post date:** [July 27, 2009, 2:46pm UTC](https://www.ruby-forum.com/t/trying-to-use-301-redirect-but-the-server-does-a-302/172750/4 "2009-07-27T14:46:35Z")

</div>

Yanni.

the “old” way is almost two years old:  
[http://dev.rubyonrails.org/changeset/7820](http://dev.rubyonrails.org/changeset/7820)  
That’s close to eternity in Rails world.

Glad I could help!

Nicolai
