The difficulty you're facing is a common one: you want to access a web application using a different URI path than the application expects. The standard Apache proxy machinery only takes care of links in the headers (e.g., Location:
headers) but not in the content of the document, so links that use absolute paths like /images/foo.png
no longer reach the right place (relative paths should usually work just fine).
A common solution is to use the mod_proxy_html module, which will let you perform substitutions in the content of your web pages. In fact, this tutorial covers exactly the situation you've described.
I don't know about .htaccess
file but I'm pretty sure this would work:
RewriteEngine On
RewriteCond %{HTTP_HOST} customer([0-9]+)\.com
RewriteRule ^/app/(.*) /app/customers/customer%1/$1 [QSA]
Explanation:
RewriteCond %{HTTP_HOST} customer([0-9]+)\.com
will put in the variable '%1
' the customer number i.e. '1
'
RewriteRule ^/app/(.*) /app/customers/customer%1/$1 [QSA]
Means: if the path begins with '/app/
' then rewrite it to /app/customers/customer
and add the variable '%1
' (i.e. '1
' in our example) so it should work with what you're asking for: rewrite to http://customer1.com/app/customers/customer1/
.
I'm sorry but your question is not really precise, and you should either giver more examples, or be more specific to what you want to do, but I did my best to help you.
You may use the RewriteMap
directive as well.
Imagine you put all your clients websites and the right directories in it like this:
alsace 1
aquitaine 2
auvergne 3
basse-normandie 4
bourgogne 5
bretagne 6
centre 7
champagne-ardenne 8
corse 9
franche-comte 10
haute-normandie 11
then I use a RewriteRule like this:
RewriteMap mapregions dbm:/web/htdocs/maps/regions.map
RewriteRule ^/region/(.*)/$ /handle_regions.php \
[NC,E=REGION:${mapregions:$1|notfound}]
So what it does is basically: if you ask for an url like /region/(.*)/
it redirects to /handle_regions.php
and sets an environment variable REGION
Then I just check if it was found: if not, I stop:
RewriteCond %{ENV:REGION} notfound
# "not found" = 404 :
RewriteRule .* - [R=404,L]
And then here you are. I'm sorry but with all the things I've just said, you have enough material to solve your problem. I don't have the time to do all the stuff for you, sorry man, I did the best I could to help you... and I hope this helps!
Best Answer
Apache does have a module for this - it's called mod_filter.