Making a 301 redirector for *everything*

I want to move my site elsewhere. So I thought I could throw in a
Webrick instance to serve as a 301 redirector on the old port and send
all the traffic to the new site. I’ve got the headers[“status”]=“301
moved permanently” and the redirect_to “http://www.newsite.com” but
what’s happening is that the basic URL (mysite.com/blog) is being
redirected (my controller is /blog), but more complex urls like
/blog/2005/09/07/abc.html are getting a “recognition failed” error.
Makes sense since there is no “2005” action.

Is there a trick I need to do in order to send every url from the old
site to the new one? While I’m in there, since my url pattern will be
staying the same, am I going to be able to keep that information as part
of the redirect or do I have to redirect to the main page of my new
site? In other words can I go from oldsite.com/blog/2005/09/07/abc.html
to newsite.com/2005/09/07/abc.html ?

Thanks!

Is there a trick I need to do in order to send every url from the old
site to the new one? While I’m in there, since my url pattern will be
staying the same, am I going to be able to keep that information as
part
of the redirect or do I have to redirect to the main page of my new
site? In other words can I go from
oldsite.com/blog/2005/09/07/abc.html
to newsite.com/2005/09/07/abc.html ?

Thanks!

Static content control

map.connect ‘/protected/*path’, :controller => ‘protected’,
:action => ‘render_static’

I use this to force any /protected URL to controller protected, action
static. I suspect you could (not tested)

Map.connect ‘/*path’, :controller => ‘redirect’, action => ‘redirect’

This map should put the whole URL in to params[:path], and call
controller redirect, method redirect for every one. You should be able
to construct an appropriate redirect from that.

Be sure to clear out /public so that rails gets the hits.

A simpler way might be to configure a redirect in your web server.
Apache and lighty can do this.

Regards,
Rich

If you’re using Apache, all you need is this in oldsite.com’s root
.htaccess:

Redirect permanent /blog http://www.newsite.com

This will catch all the stuff under /blog and pass it along to newsite.

Should be doable in Lighttpd as well, but I’m stuck on Apache at the
moment…

On 9/18/06, Duane M. [email protected] wrote:


Matt J.
[email protected]
President/Technical Director, Acme Art Company (acmeartco.org)

Where do you put this configuration line?

On Sep 18 2006, 7:45 pm, Duane M. <rails-mailing-l…@andreas-

Thanks!

A simpler way might be to configure a redirect in your web server.
Apache and lighty can do this.

Agreed. If you have apache, this is a 3-line .htaccess file in your
webroot:

RewriteEngine on
RewriteCond %{HTTP_HOST} oldsite.com
RewriteRule ^(.*) http://www.newsite.com$1

An even simpler way is to re-point oldsite.com to newsite.com in DNS,
unless you specifically wanted the 301 step inbetween.

  • Mark.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs