Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

Thats my apache config (vhost ) for that job:

RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?$ RewriteRule ^(.*)$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

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 to 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 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 – zilberas Sep 15 '09 at 14:54

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 / ProxyPassReverse / Everything works just fine. 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


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