Page 1 of 1

VERY Strange mod_rewrite behaviour

Posted: Tue Oct 04, 2005 2:26 pm
by nickvd
The .htaccess file:

Code: Select all

Options ExecCGI FollowSymLinks Includes MultiViews
RewriteEngine on
RewriteRule ^(wm|ig_common|help|servicerequest)/?(.*) http://10.32.40.3/$1/$2 [P,L]
RewriteRule ^(sharepoint)/?(.*) http://10.32.40.6/$1 [P,L]
When the url is as follows: http://www.site.com/help/it/ it works beautifully, reverse proxy to the internal IIS server works as it should, and the page loads...

When the url is as follows: http://www.site.com/help/it it fails... the url is rewritten correctly (as per the rewrite log) but the browser is redirected, not proxied to the internal ip addy (browser makes another request for http://10.32.40.3/help/it


This is causing me a major amount of grief, as I can't find a logical reason why it would be doing this. If anyone can help me, I (and my clients) would appreciate it so very very much.

Posted: Tue Oct 04, 2005 2:59 pm
by redmonkey
I suspect the problem lies more in your proxy config rather than the mod_rewrite rules.

I would guess that your internal server is attempting an HTTP redirect due to the omission of the slash.

Posted: Tue Oct 04, 2005 3:08 pm
by nickvd
So, would the problem be on the "external" server (i.e. the apache server that is doing the initial rewrite) or the "internal" server (i.e. the IIS server with the .NET app on it)?

Posted: Tue Oct 04, 2005 3:22 pm
by redmonkey
I would suspect the problem lies with the Apache proxy config and as a reasult the IIS servers are issuing an HTTP redirect. But then I really know nothing about IIS and how it handles itself so could be wrong. Also without seeing the proxy config I'm really just guessing.

You could always throw in a quick dirty hack until you figure out the real route of the cause, something like....

Code: Select all

Options ExecCGI FollowSymLinks Includes MultiViews
RewriteEngine on
RewriteRule ^(wm$|ig_common$|help$|servicerequest$) http://10.32.40.3/$1/ [P,L]
RewriteRule ^(wm|ig_common|help|servicerequest)/?(.*) http://10.32.40.3/$1/$2 [P,L]
RewriteRule ^(sharepoint$) http://10.32.40.6/$1/ [P,L]
RewriteRule ^(sharepoint)/?(.*) http://10.32.40.6/$1 [P,L]
... untested but may work.

Posted: Tue Oct 04, 2005 3:50 pm
by nickvd
It didnt work :(

However, There is no proxy configuration in the httpd.conf file, nor in the htaccess file. I'm doing a reverse proxy, and from that i could see on apache's doc's is that there is no config needed for a mod_rewrite reverse proxy...

Posted: Tue Oct 04, 2005 4:11 pm
by redmonkey
Give this a bash...

Code: Select all

Options ExecCGI FollowSymLinks Includes MultiViews
RewriteEngine on
RewriteRule ^(wm$|ig_common$|help$|servicerequest$) $1/ [R]
RewriteRule ^(wm|ig_common|help|servicerequest)/?(.*) http://10.32.40.3/$1/$2 [P,L]
RewriteRule ^(sharepoint$) $1/ [R]
RewriteRule ^(sharepoint)/?(.*) http://10.32.40.6/$1 [P,L]
You normally at least set the ProxyRequests directive to off so you don't become a proxy for the rest of the world.

Posted: Tue Oct 04, 2005 4:57 pm
by nickvd
That didnt work... it ended up redirecting to http://www.site.com/var/www/site.com/help/it ...

Posted: Tue Oct 04, 2005 5:15 pm
by redmonkey
Just double checked the rewrite rule and i'm not surprised it didn't work, for some reason I didn't notice that it/ was an extension on what you were matching.

I think ideally you need to work out which server is issuing the redirect before going much further, my money is the IIS server.

For what it's worth, I'm doing a similar thing, my config (which may or may not help) is as follows...

Code: Select all

ProxyRequests off
ProxyPass /support/ http://emma.mdf-internal.com/
ProxyPass /bugs/ http://bugs.mdf-internal.com/
ProxyPass /beta/ http://beta.mdf-internal.com/
ProxyHTMLURLMap http://emma.mdf-internal.com /support
ProxyHTMLURLMap http://bugs.mdf-internal.com /bugs
ProxyHTMLURLMap http://beta.mdf-internal.com /beta

<Location /support/>
	ProxyPassReverse /
	SetOutputFilter	 proxy-html
	ProxyHTMLURLMap	 /		/support/
	ProxyHTMLURLMap	 /support	/support
	RequestHeader 	 unset	Accept-Encoding
</Location>

<Location /bugs/>
	ProxyPassReverse /
	SetOutputFilter	proxy-html
	ProxyHTMLURLMap	/	/bugs/
	ProxyHTMLURLMap	/bugs	/bugs
	RequestHeader	unset	Accept-Encoding
</Location>

<Location /beta/>
	ProxyPassReverse /
	SetOutputFilter	proxy-html
	ProxyHTMLURLMap	/	/beta/
	ProxyHTMLURLMap	/beta	/beta
	RequestHeader	unset	Accept-Encoding
</Location>
There may well be a better solution to this, but this is working for me at present (all Apache servers)

Posted: Tue Oct 04, 2005 5:37 pm
by nickvd
I'm going to try this now, however, should it be in the conf file or can it be put in the htaccess file?

Posted: Tue Oct 04, 2005 5:47 pm
by nickvd
By the looks of it, It may just do what i want, however am i able to use it like mod_rewrite? i.e. i'd need to keep everything following the path (query string/etc) i didnt write the application that this is pointing to, so i wont be able to modify it to work...

<edit>


btw, apache is spitting out errors due to the ProxyHTMLURLMap directive, so i just commented them out...

using: "Apache/2.0.54 (Unix) PHP/4.3.11 DAV/2 Server....."

Posted: Tue Oct 04, 2005 6:01 pm
by redmonkey
In theory, it should just run as is and won't cause any problems (no guarantees though).

The HTML map stuff deals with certain styles of links that appear in the HTML files spat back to the browser, in many cases it's not required but I've used it just incase. IIRC it requires the mod_proxy_html module to be loaded.