Forum Moderators: phranque

Message Too Old, No Replies

rewrite loop fix

         

alternapop

6:59 pm on Nov 30, 2009 (gmt 0)

10+ Year Member




<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
RewriteCond %{HTTP_HOST} ^(.*)dev\.example\.edu$ [NC]
RewriteRule ^/recreation(.*)$ http://dev.example.edu/ee1/index.php/recreation$1 [P,NC]
RewriteRule ^/distribution(.*)$ http://dev.example.edu/distribution/index.php/distribution$1 [P,NC]
</IfModule>

the “recreation” rule has been working fine for months. i’m trying to get the second one, “distribution”, to work.

the error i am getting within the browser window is this:


Bad Request
Your browser sent a request that this server could not understand.
Size of a request header field exceeds server limit.
X-Forwarded-Host: dev.example.edu, dev.example.edu, dev.example.edu, dev.example.edu, dev.example.edu, dev.example.edu, dev.example.edu, dev.example.edu, dev.example.edu, dev.example.edu, dev.example.edu

i suspect that it's because of the dual reference to "distribution" and thus it's looping. am i correct? how can i fix this? though i have it working for "recreation" which contains "recreation" in both parts of the rule... so i'm not really sure what's going on.

many thanks!

jdMorgan

9:42 pm on Nov 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please describe the configuration and intent of the reverse-proxy you've implemented here. From the logged error, it appears that this server is proxied to itself, and the result is the "build up" of the X-Forwarded-Host header as the proxy function recurses.

It might also be relevant to describe why you've got a wild-card prepended to the subdomain pattern.

Jim

alternapop

9:54 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



Apple's 10.5.8 Server (Apache 2.2)

if something is there that isn't required, then it's probably out of ignorance. i probably copied it from an online example somewhere.

the GUI check box for "enable reverse proxy" is off. what about the config or error is telling you that it is on? the P flag? i can probably remove it then.

i'm just trying to hide the "index.php/distribution" part...
so that:

[dev.example.edu...]

looks like:

[dev.example.edu...]

thanks!

jdMorgan

12:04 am on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the strongest of terms, I encourage you to take your code and 'walk through it' while referring to the mod_rewrite documentation... Do not proceed past even a single character until you understand what it does. This is a server config file, and not to be taken lightly. This is absolutely not something that can safely be "cut and pasted" from some on-line source; Most on-line sources have a lot of flawed code in them, including (despite my best efforts) this forum right here.

The [P] flag invokes a reverse-proxy request to the server at the designated URL; That is, it opens a new out-going HTTP connection and sends a request to that server. So at the very least, your configuration is twice as slow as it should be, just using the original working rule, because your server is sending itself a new request via HTTP instead of just serving the content from a non-default-mapped filepath.

It seems to me that all that's needed is an internal rewrite, so that requests for the resource at URL
http://dev.example.edu/distribution/<whatever> are served with the content generated by the script at the server filepath <DocumentRoot>/distribution/index.php/distribution/<whatever>


RewriteEngine on
#
# Return 403-Forbidden response to TRACE requests
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
#
# Internally rewrite requests for URL-path /recreation/<anything>
# to filepath /eel/index.php/recreation/<anything>
RewriteCond %{HTTP_HOST} ^dev\.example\.edu [NC]
RewriteRule ^/recreation/(.*)$ /ee1/index.php/recreation/$1 [L]
#
# Internally rewrite requests for URL-path /distribution/<anything>
# to filepath /distribution/index.php/distribution/<anything>
RewriteCond %{HTTP_HOST} ^dev\.example\.edu [NC]
RewriteRule ^/distribution/(.*)$ /distribution/index.php/distribution/$1 [L]

Jim

alternapop

12:28 am on Dec 1, 2009 (gmt 0)

10+ Year Member



thanks jim!. it all makes sense now but i wasn't sure why it wasn't working obviously. this helped to clarify some things.