1
votes

I currently have a wordpress multisite setup of that consist of two sites, one is a subdomain. lets call the main domain www.domain.com and the sub domain test.domain.com

  • For both domains I need to force https
  • For the main domain I also need to enforce both ssl and www so that it becomes https://www.domain.com

The main issue I am having is when I enter https://test.domain.com this will work correctly but when I type in http://test.domain.com I get redirected to https://www.domain.com which is the main website and not the subdomain website.

<IfModule mod_rewrite.c>
RewriteEngine On

# for subdomains
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(test\.domain\.co)$ [NC]
RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]

# for main domains
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^domain\.co$ [NC]
RewriteRule ^.*$ https://www.domain.co%{REQUEST_URI} [R,L]


RewriteBase /
RewriteRule ^index\.php$ - [L]

# 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>
2
I think this question is better suited for http://wordpress.stackexchange.com rather then SO.Jeet

2 Answers

0
votes

For the subdomain, you can use this rule :

# for subdomains
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(test\.example\.com)$ [NC]
RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]
0
votes

Ok so I found the reason why I always redirected to the https version. I had originally setup the apache server to use a virtual hosts. In that file for all http request or rather port 80 e.g. <VirtualHost *:80> I had stupidly created a redirect rule of Redirect permanent / https://maindomain.co/

I resolved this issue by removing that redirect and letting my .htaccess file manage the redirects. It now works beautifully.