# 301 Redirect : domain.fr --> www.domain.com and www.domain.fr --> www.domain.com

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

-

## migrated from stackoverflow.comSep 12 '10 at 0:33

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

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

-