calvin-brand-light-mode
calvin-brand-dark-mode
∕
⌘K
About Calvin Podcast We Can Do This Book Speaking
aAbout Calvin
Podcast
wWe Can Do This Book
sSpeaking
Back

[Rails] How to do a 301 redirect

Other
Calvin Correli·Nov 5, 2005· 1 minute

I had to dig a little for this. The answer is simply:

1
2
headers["Status"] = "301 Moved Permanently"
redirect_to "/"

Here is the relevant snippet from response.rb in ActionPack:

1
2
3
4
def redirect(to_url, permanently = false)
  @headers["Status"]   = "302 Found" unless @headers["Status"] == "301 Moved Permanently"
  @headers["location"] = to_url
  ...

So as you can see, it actively checks for that particular header. Kinda weird that it doesn’t have a :status flag like so many other methods, but that’s the way it is.

Previous Deleting photos in iPhoto
Next OpenACS to Typo

Comments

Write a comment...
00:00 Recording...
calvin-brand-light-mode
calvin-brand-dark-mode
1 Chestnut Hill Plaza #1139
Newark, DE 19713
United States
Copyright © 2026 Calvin Correli
powered by