Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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..

share|improve this question

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

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

1 Answer 1

up vote 2 down vote accepted

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. :-)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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