Ecommerce Shopify WordPress Discussion

WP Multisite Child Site Redirecting to main site when not HTTPs

I have a multi-site WP installation. The main site is at https://main-site.com I have a child site https://child.org. The child site loads fine in the following variations: https://www.child.org https://child.org I'm trying to setup a redirect so that whenever a user tries to navigate to the site in HTTP, that it redirects to HTTPS. I've tried a lot of rules but all of them always redirect the HTTP child site to the HTTPS main site. After spending a long time working with the file I've come to realize that %{HTTP_HOST} is always the main site. I've also tried using %{SERVER_NAME} with the same result. My WP multisite installation is in /var/www/html My /etc/apache2/sites-available/000-default.conf contains the following: # Added to mitigate CVE-2017-8295 vulnerability UseCanonicalName On <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName $domain ServerAlias www.$domain DocumentRoot /var/www/html <Directory /var/www/html/> Options FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> My .htaccess looks like this. RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # 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] How can I update this so that %{HTTP_HOST} is the domain that the user entered into the request? Or is there another variable I can use instead of %{HTTP_HOST} and %{SERVER_NAME} that will contain the correct domain? Currently those variables always return main-site.com EDIT 1: Found this cheatsheet for .htaccess variables https://gist.github.com/fmtarif/968eaa25e165c59b21d5 I don't see any other variables that can give me what I'm looking for (the domain the user typed in), it looks like there is something wrong with the way my multi-site is setup which might be causing this. Edit 2: Here's some additional info which may be the root of the problem. I am using this domain mapping plugin for WP multisites. https://wordpress.org/plugins/wordpress-mu-domain-mapping/ The instructions in the domain mapping plugin page (in the WP backend) say "If you want to redirect a domain you will need to add a DNS "A" record pointing at the IP address of this server: {INSERT SERVER IP BELONGING TO main-site.com}" So in the hosting networking, I added an A name for child.org to be {INSERT SERVER IP BELONGING TO main-site.com}. I suppose the reason HTTP_HOST is main-site.com instead of child.org is because the change is happening at the DNS level? But how does the plugin work properly when using HTTPS? EDIT 3: When I type in https://child.org then the %{HTTP_HOST} variable is the correct child.org instead of main-site.com, but when I type in http://child.org it is main-site.com. EDIT 4: This is the MU Domain Mapping network site configuration This is the child site MU Domain mapping configuration EDIT 5: I think the root of the issue may be the file /etc/apache2/sites-enabled/000-default.conf This site only specifies the main-site.com domain. So this may be the reason why regardless of what I enter into the URL, the %{HTTP_HOST} is always main-site.com. Here is what is in that file. # Added to mitigate CVE-2017-8295 vulnerability UseCanonicalName On <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName main-site.com ServerAlias www.main-site.com DocumentRoot /var/www/html <Directory /var/www/html/> Options FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined RewriteEngine on RewriteCond %{SERVER_NAME} =main-site.com [OR] RewriteCond %{SERVER_NAME} =www.main-site.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost> EDIT 6: These are the contents of /etc/apache2/sites-enabled/000-default-le-ssl.conf <IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin webmaster@localhost ServerName $domain.com ServerAlias www.$domain.com DocumentRoot /var/www/html <Directory /var/www/html/> Options FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined Include /etc/letsencrypt/options-ssl-apache.conf ServerAlias child.main-site.com ServerAlias child.org ServerAlias child2.main-site.com SSLCertificateFile /etc/letsencrypt/live/child.main-site.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/child.main-site.com/privkey.pem </VirtualHost> </IfModule>
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.