2

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?

2
  • 1
    Your rule at a first glance seem ok to me, did you add RewriteEngine on before the rules in your .htaccess? Commented Dec 24, 2012 at 18:00
  • Regarding your "PS", yes you can! Commented Dec 24, 2012 at 18:01

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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