I'm trying to redirect my main domain non-www to www but I have this error; my add on domain redirects like this:


How can I redirect my main domain without affecting my addon domains.

My redirect code is:

RewriteCond %{HTTP_HOST}  ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.{HTTP_HOST}/$1 [R=301,L]
  • Can you post your entire .htaccess file for your main domain - the code you have posted would seem to have an obvious error and would not work as stated. However, since you are already checking the HTTP_HOST it should not affect the addon domain, which makes me think there is something else going on. Do you have any other .htaccess files? Do the addon domains have their own .htaccess files? I assume the addon domains actually point to a subdirectory off the main domains document root? – MrWhite Oct 1 '15 at 22:13

This works much better since it does a redirect on any URL without www to the www version.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
| improve this answer | |

Assuming your addon domain points to a subdirectory off the main domain's document root, then a simple workaround is to create a .htaccess file for the addon domain and simply enable the rewrite engine:

RewriteEngine On

This will prevent the parent directory's mod_rewrite directives being inherited.

However, since you already appear to be checking the HTTP_HOST in your main domain's .htaccess file then this should already be working OK, so I suspect there is something else going on.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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