简体   繁体   中英

WordPress Multisite, multiple domains and subdomains with .htaccess

I've got a WordPress multisite installation with the following workflow for onboarding sites:

  1. Site is set-up with subdomain URL and the content is built. Eg, https://aclientsite.mydomain.com/

  2. Once the site is ready to take live, the site URL is changed to the client's domain name. Eg, https://www.aclientsite.com/

  3. Run Interconnect.it serialized data updater to change the tables' content to account for the new URL

The problem I have is forcing WWW and SSL reliably for the final production URLs.

I should note that I only have access to .htaccess, not the Apache config.

Here's the entire contents of my .htaccess file:

# Force www: from http://stackoverflow.com/a/4958847/1078583    
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Force SSL: From http://stackoverflow.com/q/24322035/
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# BEGIN WordPress
RewriteEngine On
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]

# END WordPress

The problem here is that it adds WWW to my subdomain-ed non-prod sites as well. Eg, https://www.aclientsite.mydomain.com/

This obviously breaks the non-prod sites. I've tried adding www to the non-prod site URL configuration, but for some reason WordPress doesn't like that. It strips out the www and scheme when I try that. Eg, if I input https://www.aclientsite.mydomain.com/ it saves it as ://aclientsite.mydomain.com/

Any thoughts on how I can accomplish my goal?

在第一个RewriteRule之前添加一个条件:

RewriteCond %{HTTP_HOST} !mydomain.com [NC]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM