We run a site based on Zend Framework using apache httpd (2.2) with mod_rewrite for SEO and usability friendly URL:s. Recently we added mod_proxy (and mod_proxy_balancer, mod_proxy_http, mod_rpaf) for setting up a loadbalancer virtual-host.

Our setup now looks like:

external.site.com (vhost on server1.site.com with reverse proxy)
|-internal1.site.com (vhost on server1.site.com) 
|-internal2.site.com (vhost on server2.site.com)

Where internal1 & internal2 serves most of the dynamic content and external serves static content plus some admin type pages. All the vhosts have got the same code and .htaccess setup.

The problem is that on external.site.com the RewriteRule doesn't add the correct headers to the request environment, specifically REDIRECT_URL which we and ZendFramework depend upon. Everything works fine for the requests that are forwarded to the internal vhosts.

The relevant parts of the httpd.conf:

<VirtualHost *:80>
  ServerName external.site.com
  DocumentRoot /opt/www/htdocs/
  CustomLog "/var/log/httpd-proxy-access.log" combined

  <Proxy balancer://backend/>
    Balancermember http://internal1.site.com
    Balancermember http://internal2.site.com
    ProxySet lbmethod=byrequests
  ProxyRequests Off
  <Proxy *>
    Order deny,allow
    Allow from all
  ProxyPass /static/ !
  ProxyPass /config/ !
  ProxyPass / balancer://backend/
  ProxyPassReverse / balancer://backend/
<VirtualHost *:80>
  ServerName internal1.site.com

  RPAFenable On

From the .htaccess file:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^.*robots.txt
RewriteCond %{REQUEST_URI} !^.*/static/.*
  RewriteRule .* index.php [L]

php_flag magic_quotes_gpc off 
php_flag register_globals off

Because there only is a problem on the external vhost we assume it is a problem with the mod_proxy and mod_rewrite combination. Any ideas?



I am by no means an expert, but I had to put [OR] to my file. As stated here

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^.*robots.txt [OR]
RewriteCond %{REQUEST_URI} !^.*/static/.*
RewriteRule .* index.php [L]
  • As these are two "not" comparisons, anything - including robots.txt or /static/ - will match, if you use an [OR], which means everything gets rewritten. The goal here was to say "redirect everything EXCEPT robots.txt and /static/ to index.php", so I believe it was correct as written. – crb Jun 12 '09 at 23:34
  • I had this problem recently - this gets messy real quick but this rule should work RewriteCond %{REQUEST_URI} !^.*(/static/)?(robots.txt)?$ [NC] – DisabledLeopard Aug 4 '09 at 1:20

I don't know if this applies to your application or not but couldn't you use the content of $_SERVER["REQUEST_URI"] instead?

  • 1
    I'm affraid not. When using mod_rewrite REQUEST_URI is changed to reflect the URI of the script instead of the one the client requested. – Paso Jun 23 '09 at 10:21

Have you tried something like:

RewriteRule .* index.php [L,E=REQUEST_URL:$ENV{'REQUEST_URL'}]

Basically the idea is to pick it up from one environment and just shovel it along to the next one. Not sure it that'll work but can't hurt to try.


I believe we worked around this issue by upgrading Zend Framework, later versions don't depend on REQUEST_URL. It appears REQUEST_URL has different behaviour depending on which modules are installed. See this mailing-list thread

Your Answer

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

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