Wordpress Multisite with Wildcard Certificates not mapping correctly
-
15-04-2021 - |
题
I have set up a Wordpress Multisite with LAMP successfully and it currently has the following structure
- a.com (wordpress primary domain)
- a1.a.com
- b.com
- b1.b.com
- b2.b.com
- b3.b.com
- c.com
I created virtual hosts configurations for the three domains mapping to the same WordPress Multisite directory, and I am running the WordPress MU Domain Mapping plugging to handle redirections and so far has been working great with http.
Then I created the certificates for https:
- cert 1 => a.com, *.a.com
- cert 2 => b.com, *.b.com
- cert 3 => c.com
And set automatic https redirecting in the virtualhost configuration for all the domains.
Current status:
- a.com and a1.a.com are working with https, but a1.a.com required plugins for redirection from http to https.
- b.com is working with https
- b.com subdomains are not working with https, pluggins have led to use *.a.com certificate which results in security warning for all sites.
- c.com is working with https.
Can someone please help me understand where can the problem be?
I'm thinking about creating a virtual host configuration for each subdomain in b.com, but it will be more like a patch than a fix.
解决方案
It seems that I was getting wrong the virtual host configuration file to redirect all http requests to https
This is my current working configuration:
/etc/apache2/sites-available/a.com.conf
<VirtualHost *:80>
ServerAdmin admin@a.com
ServerName a.com
ServerAlias *.a.com
DocumentRoot /var/www/a.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =a1.a.com [OR]
RewriteCond %{SERVER_NAME} =a.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
/etc/apache2/sites-available/a.com-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@a.com
ServerName a.com
ServerAlias *.a.com
DocumentRoot /var/www/a.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/a.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/a.com/privkey.pem
</VirtualHost>
</IfModule>
However it is required to update the virtual host configuration RewriteCond %{SERVER_NAME} =a1.a.com [OR]
for every subdomain I need, therefore the process is not automated.