• Hi,
    I have a WordPress multisite directory with SSL.

    I have a multidomain certificates with extra certificates for the subsite domain names with www but would prefer not to buy a certificate for the non www. I’m using domain mapping where I use the www version as the primary version and where the non www version gets 301 redirected into the www version.

    In htaccess I changed:
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,NC,L]

    Into:
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

    This works nicely with the childsites. They get redirected without warnings in Edge and Firefox. But the mainsite also gets redirected from mainsitename.com to https://www.mainsitename.com which I don’t want.

    How can I change the htaccess so that it https redirects the childsites from non www to www but leave the mainsite unredirected?

Viewing 2 replies - 1 through 2 (of 2 total)
  • you can try this, though it assumes that you are not doing domain mapping to subsites – if you are (or do in future) then you’ll need to get a little fancier in the non-www to www redirects (unless you want all mapped domains to also use www)… also, ymmv ??

    ### BEGIN WWW and HTTPS REDIRECTS
    <IfModule rewrite_module>
    ## BEGIN non-WWW to WWW only for Network Subsites
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\ HTTP/ [NC]
    RewriteCond %{HTTP_HOST} !\.mainsitename\.com$ [NC]
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]
    ## END non-WWW to WWW only for Network Subsites
    ## BEGIN HTTPS Catch-All
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\ HTTP/ [NC]
    RewriteCond %{HTTPS} !=on [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]
    ## END HTTPS Catch-All
    </IfModule>
    ### END WWW and HTTPS REDIRECTS
    Thread Starter handig

    (@handig)

    Thanks, but it seems to add a double “www”.

    For example when I type in subsitename.com it seems to change in https://www.www.subsitename.com.

    BTW I use domainmapping, but prefer to use the www variants as prefered domain anyway.

    I enclosed my complete htaccess code here:

    <Files wp-login.php>
    Order Deny,Allow
    #Deny from all
    Allow from 83.117.224.220
    </Files>
    
    # BEGIN WEBSITE SPEED BOOST
    # Time cheat sheet in seconds
    # A17200 = 5 uur
    # A86400 = 1 day
    # A172800 = 2 days
    # A2419200 = 1 month
    # A4838400 = 2 months
    # A29030400 = 1 year
    
    <IfModule mod_headers.c>
    <FilesMatch "\.(js|css|flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|gif|jpg|jpeg|png|swf)$">
    Header append Cache-Control "public"
    </FilesMatch>
    <FilesMatch "\.(txt|html)$">
    Header append Cache-Control "proxy-revalidate"
    </FilesMatch>
    <FilesMatch "\.(php|cgi|pl|htm|xml)$">
    Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
    Header set Pragma "no-cache"
    </FilesMatch>
    </IfModule>
    
    <IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault A300
    ExpiresByType image/jpg A4838400
    ExpiresByType image/gif A4838400
    ExpiresByType image/png A4838400
    ExpiresByType image/jpeg A4838400 
    ExpiresByType application/x-shockwave-flash A4838400
    ExpiresByType application/x-javascript A17200
    ExpiresByType application/javascript A17200
    ExpiresByType text/javascript A17200
    ExpiresByType text/css A300
    ExpiresByType text/html A300
    </IfModule>
    
    <IfModule mod_deflate.c>
    # Compress everything except images
    
    # Insert filter
    SetOutputFilter DEFLATE
    
    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    
    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    # Don't compress images
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    
    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
    </IfModule>
    # END WEBSITE SPEED BOOST
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    ### BEGIN WWW and HTTPS REDIRECTS
    <IfModule rewrite_module>
    ## BEGIN non-WWW to WWW only for Network Subsites
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\ HTTP/ [NC]
    RewriteCond %{HTTP_HOST} !\.mainsitename\.com$ [NC]
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]
    ## END non-WWW to WWW only for Network Subsites
    ## BEGIN HTTPS Catch-All
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\ HTTP/ [NC]
    RewriteCond %{HTTPS} !=on [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]
    ## END HTTPS Catch-All
    </IfModule>
    ### END WWW and HTTPS REDIRECTS
    
    # add a trailing slash to /wp-admin
    RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    </IfModule>
    
    # END WordPress
    
    # disable directory browsing
    Options All -Indexes
    
    <Files .htaccess>
    order allow,deny
    deny from all
    </Files>
    
    <Files wp-config.php>
    order allow,deny
    deny from all
    </Files>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multisite htaccess redirect non www to www’ is closed to new replies.