2

I work as a sysadmin at a large academic department. We have an apache httpd, with a WP subdirectory multisite installation, fronted by an apache reverse proxy. In this setup we want to allow our users to serve WP content under the main domain name (external.com, say) with their own name attached (user1):

The vhost config looks like

  # ...
  RequestHeader set X-Forwarded-Proto "https"

  ProxyPass        / http://internal.com/
  ProxyPassReverse / http://internal.com/
  ProxyPreserveHost On
  # ...

This allows us to assign users their own wp sites, as user1, with siteurl and host both set to https://external.com/wpsites/site1, and they can edit and publish.

And we want to add sites for whole research projects, with their own domain names, that should be addressed as a bare domain name: https://project1.com. I've set the vhost config like this:

  # ...
  RequestHeader set X-Forwarded-Proto "https"

  ProxyPass        / http://internal.com/wpsites/project1
  ProxyPassReverse / http://internal.com/wpsites/project1
  ProxyPreserveHost On
  # ...

With siteurl and host both set to https://project1.com, this gives a 404 error on the root, with an 'Oops!' for the home page, and goes into 301 loops on permalinks.

With siteurl and host both set to https://external.com/wpsites/project1, there is a redirect to the main site root when trying https://project1/, but the permalinks work ...

The rewrite rules look like

RewriteEngine On
RewriteBase /wpsites/
# if req NOT lastly from reverse proxy, redirect thru it
# -- 'cause direct access doesn't work
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111$
RewriteRule ^(.*)$ https://external.com/wpsites/$1 [R=301,L]

RewriteRule ^index.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

EDIT: additional configuration that may shed some light:

  • the WP site is in a subdirectory of the httpd docroot (it's implicitly mentioned above)
  • the domain is set to project1 and the path to / in the wp_blogs table

Is this possible, at all? How, in that case? Changes to the .htaccess file? To the vhost config? To the siteurl and host options? Move the site to the docroot? Change the domain/path values in the wp_blogs table?

  • Does it work if you make the vhost config for project1.com the same as for the user sites and then try to access it through project1.com/wpsites/project1 ? I would assume it would. This points to the RewriteBase of /wpsites/ in the .htaccess then being the issue for the project1 sites – mozboz Jun 15 '20 at 16:11
  • @mozboz, yes that does work -- but it's not only the vhost config that changes, the site_url/home options are also different. – Staffan Bergh Jun 15 '20 at 18:46
  • Yes, understood that the site_url and home options are different. You have this one .htaccess for all sites, right? Sorry I don't have an exact answer for you, but I'm wondering if it's to do with wpsites being part of the public URL in the User ones, but not in the Project ones, and if this is likely interacting with the /wpsites/ in the rewrite rules. – mozboz Jun 15 '20 at 22:28
  • Have you leaved the domain URL for each site inside the WP settings inside the network? WordPress supports different URLs for each site in the Multisite. A redirect via .htaccess or similar is not always necessary. Have you looked at this answer wordpress.stackexchange.com/questions/181914/… – bueltge Jun 17 '20 at 6:51
  • @bueltge I think I've tried all combinations of home and siteurl: both https://project1, both https://external.com/wpsites/project1, one one way, and the other the other way. I'll carefully run thru these combinations again, but as I remember, no combination gave a (ultimate) 200 both on https://project1.com and on sub-paths (i.e. https://project1.com/about/). – Staffan Bergh Jun 18 '20 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.