How do i force www subdomain on both https and http
        Posted  
        
            by 
                Brian Perin
            
        on Pro Webmasters
        
        See other posts from Pro Webmasters
        
            or by Brian Perin
        
        
        
        Published on 2010-12-02T13:09:30Z
        Indexed on 
            2011/01/01
            13:59 UTC
        
        
        Read the original article
        Hit count: 489
        
For whatever reason I can't seem to get this right, I've looked at many examples on here and apache's website. I'm trying to force www.domain.com instead of domain.com on EITHER http or https but I am not trying to force https over http.
the following code seems to work for all https connections but http will not redirect to www.
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^ http://www.domain.com%{REQUEST_URI} [R=301]
        © Pro Webmasters or respective owner