views:

394

answers:

2

I need to send all requests for the directory home/alphauser to backend/alphauser, but not requests to files inside the home/alphauser directory. For example:

http://home/alphauser            ->   http://backend/alphauser
http://home/alphauser/           ->   http://backend/alphauser
http://home/alphauser/icon.png   ->   http://home/alphauser/icon.png
http://home/alphauser/index.html ->   http://home/alphauser/index.html

I created an ".htaccess" file in the home/alphauser/ directory with the following:

RewriteEngine on
RewriteRule ^$ http://backend/alphauser [P]

mod_rewrite allows for access to files inside the home/alphauser/ directory as expected, but when the directory itself is requested either with or without the slash:

http://home/alphauser
http://home/alphauser/

..the browser (firefox) presents a file download popup that states:

You have chosen to open a file which
is a: httpd/unix-directory

The contents of the file is the proper html from backend/alphauser (which is the url pattern to a JSP) so the payload returned is correct. It seems as though apache is sending back this strange mime type of "httpd/unix-directory"

Help!

A: 

Robert,

this seems to be weird to me

RewriteEngine on
RewriteRule ^$ http://backend/alphauser [P]

the regular expression you made basically match anything fair enougth but it would not pass the URI to the backend.

RewriteEngine on
RewriteRule ^/alphauser/$ http://backend/alphauser [P]

or

RewriteRule ^/$ http://backend/alphauser [P]

I am not 100 % sure how mod_rewrite behave in a .htaccess file

This would make much sense it my opinion, also you have to make sure you have mod_proxy and mod_proxy_http enabled or it won't work.

RageZ
No luck.mod_proxy is enabled because I'm already using ProxyPass and ProxyReversePass directives in apache2.conf.
Robert
Actually, the regular expression ^$ is intended to match no files and only the directory. I'm not interested in passing the URI - .htaccess is in the alphauser directory already - so the URI to pass is already known. I want requests to the /alphauser/ directory itself to pass through to a Servlet/JSP and other requests to proceed normally.
Robert
I will edit my answer
RageZ
I appreciate your help. I tried your suggestion of `RewriteRule ^/$ http://backend/alphauser [P]` and it didn't pass through to the JSP for a url of `http://home/alphauser`. I looked at the rewrite logs and it showed: `applying pattern '^/$' to uri ''` which evaluates to false because the string doesn't start with `/`
Robert
oky then your `^$` was ok, do you have some access to the backend server ?
RageZ
A: 

It turns out the problem had nothing to do with mod_rewrite. My backend was not sending a ContentType header at all. Once I set it to populate the ContentType as text/html everything worked.

Robert