apache.htaccessmod-rewriterewritemap

Why did my mod_proxy flag stop working in htaccess?


I've created a RewriteMap to handle a large number of domain proxies. My rewrite conditions looks like this:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
  RewriteRule ^ - [E=MAPTO:${rewritemap:%1}]
  RewriteCond %{ENV:MAPTO} !=""
  RewriteRule ^.*$ http://exampledomain.com/%{ENV:MAPTO}/$0/ [P,NC]
</IfModule>

Basically, my RewriteMap will look at the domain coming in, match it to an entry in a database, and return something like "user/userid".

This would, for example, display the incoming domain in the address bar, but display the content returned at http://exampledomain.com/user/userid/

Now, for some reason, I'm getting a 301 redirect to http://exampledomain.com/user/userid/ — no proxy. What could be causing this?


Solution

  • Welp, it's because I turned on output buffering. From the Apache doc:

    Be sure to turn off buffering in your program.

    Turned it off and now it's working.

    Update

    This, apparently, did not solve the problem. Not sure why it seemed to work and now isn't. If anyone else has any suggestions, I'll take them.

    Update 2

    Okay, this time I removed the trailing slash and it seems to work:

    RewriteRule ^.*$ http://exampledomain.com/%{ENV:MAPTO}/$0 [P,NC]
    

    I'm guessing if the incoming domain had no directory or file names it was closing with a double trailing slash and this was causing the page to redirect.