Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to convert a freshly-installed and functional WordPress into a multisite network. But I'm having problems because of our Apache configuration.

We use Apache to randomly redirect requests for domain.com to one of two application servers: app1.domain.com or app2.domain.com. The problem is that WordPress redirects to DOMAIN_CURRENT_SITE (defined in wp-config.php) if the current browser domain differs from that. This results in a 310 redirect loop. Here's an example of what happens:

  1. User requests domain.com/apps/wordpress/
  2. Apache redirects to app1.domain.com/apps/wordpress/
  3. Because redirect domain does not match DOMAIN_CURRENT_SITE, WordPress redirects to DOMAIN_CURRENT_SITE (domain.com/apps/wordpress/)
  4. Return to step 1 and repeat

What I'd like to do is set all WordPress links and URLs to domain.com and have WordPress ignore the fact that app1.domain.com or app2.domain.com is actually being retrieved. Is this possible?

Here are the relevant Apache conf files (simplified), in case I'm not being quite clear:

application_servers.conf:

domain.com-prod-http  app1.domain.com:80|app2.domain.com:80

httpd.conf:

RewriteMap server rnd:conf/application_servers.conf
RewriteRule ^/apps/*([^/]*)/*(.*) http://${server:domain.com-prod-http}/apps/$1/$2 [P,L,QSA]
share|improve this question

1 Answer 1

up vote 1 down vote accepted

After banging my head on this for a few days, I found a solution that works.

Just add the following to wp-config.php:

if ( isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ) {
    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}

This will force WordPress to use the requested domain, instead of the proxy domain.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.