HTTP to HTTPS redirects for Multisite Setups

Events happening in the community are now at Drupal community events on www.drupal.org.
billp44ruby's picture

I've got a multisite installation set up in a subdomain implementation. I've got an SSL certificate on the subdomain and I'd like to make sure all http traffic that comes at the site is redirected to https. My research shows that in normal implementation, an update to the .htaccess file would be the route to go. But since there is a single .htaccess file for the Drupal code, I'm not sure how to make this work only for my subdomain implementation.

Any suggestions?

Comments

use RewriteCond %{HTTP_HOST}

eporama's picture

You can specify the domain you want to use with the RewriteRule using a condition right before it.


RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This works for multisite to

keva's picture

This works for multisite to redirect a specific domain, and leave others untouched.

You may need to edit it for a subdomain.


To redirect all www. and non-www. requests to https://non-www :

RewriteCond %{HTTP_HOST} ^www.SPECIFICDOMAIN.com$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.)$ https://SPECIFICDOMAIN.com/$1 [L,R=301]



To redirect all www. and non-www. requests to https://www :
RewriteCond %{HTTP_HOST} ^www.SPECIFICDOMAIN.com$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.)$ https://www.SPECIFICDOMAIN.com/$1 [L,R=301]



In each case, replace SPECIFICDOMAIN with your domain

+1 to eporama. That worked

amandap's picture

+1 to eporama. That worked for me!

Thank you keva!

mraichelson's picture

Your example solved what we spent a couple days trying to track down an answer to.

HTTP to HTTPS for Drupal 8 multisite

londova's picture

This doesn't work for Drupal 8.
Any idea how it should look in Drupal 8?

Multisite

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: