Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I searched web for several days but didn't found solution for my problem. Lets say I have a web application (written in Ruby on Rails with apache passenger mod) running at mydomain.com

All I need is to rewrite users pointing to www.domain2.com to domain2.mydomain.com leaving users browser at www.domain2.com but "catch" subdomain string in my application.

Thats my apache config (vhost domain2.com ) for that job:

RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?domain2.com$ RewriteRule ^(.*) http://domain2.mydomain.com$1 [P,R=301,L]

but it's not working. Everything works (it points to my app and so on) but application catches "www" subdomain string (that is on users browser) but not expected one.

RewriteRule without "P" flag works just fine. My app catches right domain name (domain2), but URL changes in users browser (to domain2.mydomain.com)

What should I do. Maybe it's impossible to do such trick?

Thanks a lot for an answer.

share|improve this question
    
Please be more specific about what you mean by "catching a subdomain string". –  earl Sep 14 '09 at 17:32
    
Problem is that I need to identify from witch domain a request come in my application.I want to rewrite (somehow) request to www.domain2.com to domain2.mydomain.com where my app is.If I have such a request,I know that it came from domain2.There are methods/functions in ruby language to work with subdomains,and I can "catch" subdomain value(string) of a request and do next things (it's out of article).But I need to leave www.domain2.com in users browser.Like I explaned below, it seems that I need to rewrite http request headers before they come into my app and then restore them on response.how? –  zilberas Sep 15 '09 at 14:54

1 Answer 1

Using the P (proxy) and R (redirect) flags in your RewriteRule at the same time does not make much sense. You should use only the P (proxy) flag.

See here for details on reverse proxy setups with Apache httpd and its mod_proxy.

share|improve this answer
    
Thank you joschi for your answer. Yes I tried reverse proxy feature: ProxyPass / domain2.mydomain.com ProxyPassReverse / domain2.mydomain.com Everything works just fine. www.domain2.com points to my app, but I still can't catch subdomain string. That means I can't identify from witch domain it came. I still have "www" - like on users browser. I really don't know what to do. It seems that I should rewrite http headers somehow before it come to my app, and then restore them again when sending response to user, but I really donno how to do it.. :( –  zilberas Sep 15 '09 at 14:27
    
and yes I tried to leave only P flag, but with no success.. –  zilberas Sep 15 '09 at 14:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.