0

We're trying to setup Apache on a public server to proxy requests to Apache with WordPress on another server, but we're getting infinite redirect loops.

Requests starting with www.example.com/about should get proxied to the internal server wp.example.corp. e.g.

www.example.com/about/about/team => proxy => wp.example.corp/about/team

To further complicate matters, our WordPress installation is in a subdirectory called "wp". So, on the WordPress server, we have the following settings:

Here are some of the relevant bits from the Apache config on the public server:

<VirtualHost *:80>
  #...
  ProxyPreserveHost On
  ProxyRequests off
  ProxyErrorOverride On
  <Proxy *>
    Order allow,deny
    Allow from all
  </Proxy>


  RewriteCond %{REQUEST_URI} ^/about/?$
  RewriteRule ^/about/?$ http://wp.example.corp/ [P,L]

  RewriteCond %{REQUEST_URI} ^/about/.+
  RewriteRule ^/about/(.*) http://wp.example.corp/$1 [P,L]

  #...
</VirtualHost>

The Apache config on the WordPress server is pretty straightforward:

<VirtualHost *:80>
  #...
  DocumentRoot /var/lib/publicpages

  <Directory /var/lib/publicpages/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride FileInfo Indexes Limit Options
  </Directory>
</VirtualHost>

And here is the .htaccess file from the root of the WordPress server:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

With LogLevel set to debug, I can see the requests hitting the public server and responding with 301 redirects:

x.x.x.x, y.y.y.y (y.y.y.y) - - [25/Jan/2012:16:44:28 -0600] "GET /about/about/team/ HTTP/1.1" 301 20 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2"
x.x.x.x, y.y.y.y (y.y.y.y) - - [25/Jan/2012:16:44:28 -0600] "GET /about/about/team/ HTTP/1.1" 301 20 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2"

And I can see the same requests hitting the WordPress server, who is responding with 301 redirects:

z.z.z.z - - [25/Jan/2012:16:44:28 -0600] "GET /about/team/ HTTP/1.1" 301 20 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2"
z.z.z.z - - [25/Jan/2012:16:44:29 -0600] "GET /about/team/ HTTP/1.1" 301 20 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2"

I also enabled full Rewrite logging on the WordPress server and see the following repeated over and over again:

x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (3) [perdir /var/lib/publicpages/] add path info postfix: /var/lib/publicpages/about -> /var/lib/publicpages/about/team
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (3) [perdir /var/lib/publicpages/] strip per-dir prefix: /var/lib/publicpages/about/team -> about/team
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (3) [perdir /var/lib/publicpages/] applying pattern '^index\.php$' to uri 'about/team'
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (3) [perdir /var/lib/publicpages/] add path info postfix: /var/lib/publicpages/about -> /var/lib/publicpages/about/team
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (3) [perdir /var/lib/publicpages/] strip per-dir prefix: /var/lib/publicpages/about/team -> about/team
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (3) [perdir /var/lib/publicpages/] applying pattern '.' to uri 'about/team'
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (4) [perdir /var/lib/publicpages/] RewriteCond: input='/var/lib/publicpages/about' pattern='!-f' => matched
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (4) [perdir /var/lib/publicpages/] RewriteCond: input='/var/lib/publicpages/about' pattern='!-d' => matched
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (2) [perdir /var/lib/publicpages/] rewrite 'about/team' -> 'index.php'
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (3) [perdir /var/lib/publicpages/] add per-dir prefix: index.php -> /var/lib/publicpages/index.php
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (2) [perdir /var/lib/publicpages/] trying to replace prefix /var/lib/publicpages/ with /
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (5) strip matching prefix: /var/lib/publicpages/index.php -> index.php
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (4) add subst prefix: index.php -> /index.php
x.x.x.x - - [26/Jan/2012:09:54:04 --0600] [www.example.com/sid#80e06c20][rid#80fa4200/initial] (1) [perdir /var/lib/publicpages/] internal redirect with /index.php [INTERNAL REDIRECT]

What am I missing?

5
  • Seems like the Wordpress application code may be sending that redirect, since the Apache configuration shouldn't be. The one oddity I see is that your last RewriteRule should be RewriteRule . index.php [L] instead of RewriteRule . /index.php [L] - it's adding an extra slash, due to the RewriteBase. But, I doubt that's the issue - capture the request headers and see what Location: is pointed to in the redirects? Jan 25, 2012 at 23:00
  • Location is "-". Content-Location is "-". Host is "www.example.com". I also fixed the extra slash from the RewriteRule, but not luck. Jan 25, 2012 at 23:11
  • That's.. very strange. Well, let's narrow it down to either Apache or Wordpress - in its vhost config, set a RewriteLog location that Apache can write to and set RewriteLogLevel 9 - if Apache's not doing anything crazy with the request, then we can be sure that Wordpress is the culprit and go from there. Jan 25, 2012 at 23:42
  • Excellent suggestion. I have updated my question with the RewriteLog output. Looks like Apache is behaving itself, at least to my eyes. Jan 26, 2012 at 16:00
  • Yeah, that looks like exactly what it's supposed to be doing, and it's certainly not sending a redirect, so I think we're looking at Wordpress misbehaving. Unfortunately, I'm not familiar enough with it to be too helpful on that front.. Jan 26, 2012 at 16:42

2 Answers 2

0

We gave up and just made the URLs/paths match in both Apache servers. E.g.

www.example.com/about/about/team => proxy => wp.example.corp/about/about/team

While that doesn't exactly fix the issue, it effectively sidesteps the problem and eliminates the redundant 301 redirects.

-1

You could use ProxyPass to do this, instead of using a Rewrite rule.

ProxyPreserveHost On
ProxyPass /about/ http://wp.example.corp/
ProxyPassReverse /about/ http://wp.example.corp/
1
  • I'm not sure why ProxyPass would be different - I believe it's functionally equivalent to using a Rewrite rule with a proxy. I think both use mod_proxy under the hood. That said, strangely enough, I can't get ProxyPass to work at all in this case. Jan 27, 2012 at 15:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .