Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to set a redirection in my VirtualHost configuration for my website. So far I am able to redirect non www trafficto the www address like this :

<VirtualHost: *:80>
    ServerAlias www.gcbeauce.com
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^guidedescommercesdebeauce\.com$ [NC]
    RewriteRule ^(.*)$ http://www.guidedescommercesdebeauce.com$1 [R=301,L]

But what I also want is to redirect the old domain to this new one. I have tried adding :

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

But nothing happens.

Am I missing something here?

share|improve this question
    
While your machine might be running Ubuntu, an Apache question like this one might get a better result on serverfault.com. –  Windigo Feb 1 '11 at 16:26

2 Answers 2

You need to negate the match. Try this:

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

Notice the exclamation mark in the RewriteCond. Note also that this will force a single canonical domain name. I'm assuming this is what you want. If not, then you'll have to enumerate the domain names to be redirected. In that case, be sure to add [OR] to the end of the RewriteCond.

I've also added [QSA] to your flags. That way, any query string that might exist will be preserved.

Finally, you are strongly urged to read the mod_rewrite documentation carefully, as it has answers to this and many other questions.

share|improve this answer

Missing a slash before $1?

RewriteEngine On
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]
share|improve this answer
1  
Adding the extra slash will make the url looks like : new-domain.com//something in this case. –  Sebastien Lachance Feb 1 '11 at 16:09

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.