Force HTTPS for individual domains within WP multisite

Keywords: WordPress Multisite - AWS - How to - Secure Connections (SSL/HTTPS)
I have a multisite setup. 1 main domain with 5 subdomains. I created one SSL certificate that includes all 6 domains. I forced the HTTPS redirect with

DocumentRoot "/opt/bitnami/apache2/htdocs" RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^(localhost| RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L] ...

It all works as long as the web user actually includes the https in the url, but if they don’t the redirect only goes back to the main domain, not one of the subdomains.

Heres the support bundle if you want to see my set up: 0bdc3575-adaa-4ab7-9a07-c31ca881654a

Question: am I suppose to edit the httpd-vhosts.conf file instead of what I did above? I tried it one time and didn’t seem to do anything.

Many thanks in advance


That RewriteRule line redirects all the http requests to https://%{SERVER_NAME} and SERVER_NAME is probably the main domain. You need to use “HTTP_HOST” to redirect to https using the same domain the user used in the request.

<VirtualHost default:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^(localhost|
  RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [R,L]

Let us know if that works for you :slight_smile:

Happy to help!

Was my answer helpful? Click on :heart:

1 Like

Thank you, that worked!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.