Mobile app version of vmapp.org
Login or Join
Odierno851

: Non-www to www Redirects I'm trying to redirect my main domain non-www to www but I have this error; my add on domain redirects like this: http://www.example.org/example.org/ How can I redirect

@Odierno851

Posted in: #Htaccess #Redirects #Url #UrlRewriting

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

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

My redirect code is:

RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ www.{HTTP_HOST}/ [R=301,L]

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Odierno851

2 Comments

Sorted by latest first Latest Oldest Best

 

@Nickens628

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 ^(.*)$ www.example.com/ [R=301,L]

10% popularity Vote Up Vote Down


 

@Ann8826881

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme