简体   繁体   中英

mod_rewrite proxy RewriteRule not working

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM