0

I'm using a Apache2 server with Passenger for my Rails app.

I dunno how to create a 301 redirect in my VirtualHost as :

  • domain.fr --> www.domain.com
  • www.domain.fr --> www.domain.com

I've tried :

Redirect 301 / http://www.domain.com/

and

Redirect permanent / http://www.domain.com/

But it's not the way to do it :-)

Thx for your answers..

migrated from stackoverflow.com Sep 12 '10 at 0:33

This question came from our site for professional and enthusiast programmers.

2

Use mod_rewrite to do this. This article shows some examples, here's their way to rewrite non-www. to www.:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

For your purposes, I'd also extend this with the following:

RewriteCond %{HTTP_HOST} ^www.domain\.fr$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^domain\.fr$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

Of course, the last two could be combined with the proper regex modification in the RewriteCond. I'll leave this as an exercise for you, so you have an incentive to learn more about mod_rewrite. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.