Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

301 Wildcard. I don't think I am doing it right. Need domain1.com/keyword5 to go to domain2.com/keyword5. Instead it does this:

www.domain1.com/keyword5 goes to www.domain2.com (tld, root, not the keyword5 directory)

Here is my .htaccess:

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

PS: Can I do multiple domains on the same .htaccess? For example, I have 3 domains on the same public_html, can I 301 each of them like this?

share|improve this question
1  
Your rule at a first glance seem ok to me, did you add RewriteEngine on before the rules in your .htaccess? –  Marco Demaio Dec 24 '12 at 18:00
    
Regarding your "PS", yes you can! –  Marco Demaio Dec 24 '12 at 18:01
add comment

1 Answer

Your .htaccess actually looks OK-ish to me, in that it should work, although it can be simplified:

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

The RewriteRule substitution is a string, not a regex, so no need to escape everything. In fact you never need to escape forward slashes in .htaccess. No need for the double quotes either.

share|improve this answer
add comment

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.