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 have a site that has dynamic virtual subdomains using mod_rewrite, as defined like this:

<VirtualHost *:80>
    ServerAlias    *

    DocumentRoot    /var/www/

    RewriteEngine    on
    RewriteCond    %{HTTP_HOST}    ^[^.]+\$
    RewriteRule    ^(.+)            %{HTTP_HOST}$1    [C]

    RewriteRule    ^([^.]+)\*)    /var/www/$1$2


The problem is that I want a specific url, say to point back to using a proxy (not url redirecting).

I have tried adding:

RewriteRule ^([^.]+)\*)    /var/www/$2 [P]

But that didn't work. Any ideas?

share|improve this question

From the RewriteRule docs section on [P]:

You must make sure that the substitution string is a valid URI (typically starting with http://hostname) which can be handled by the Apache proxy module.


RewriteEngine on
RewriteCond   %{HTTP_HOST}              ^$
# [L] means stop processing after this rule
RewriteRule   ^/CONTROL/(.*)  $1 [P,L]

RewriteCond   %{HTTP_HOST}              ^[^.]+\$
RewriteRule   ^(.+)                      %{HTTP_HOST}$1

RewriteRule   ^([^.]+)\*) /var/www/$1$2

Make sure you have the proxy modules loaded. If you have trouble enable verbose logging with:

RewriteLog      /path/to/rewrite.log
RewriteLogLevel 9
share|improve this answer
The thing is, I don't just want, I also want all my other virtual subdomains to have the same feature, e.g. So I did this: RewriteEngine on RewriteCond %{HTTP_HOST} ^[^.]+\$ RewriteRule ^(.+) %{HTTP_HOST}$1 RewriteRule ^/CONTROL/(.*)$1 [P,L] RewriteRule ^([^.]+)\*) /var/www/$1$2 The log says it's applying the patter /CONTROL(.*) to the url, but it never maps to the primary domain, treating CONTROL as a directory – Tony G. Sep 6 '09 at 19:01
Can you show us the rewrite log for one request? Instead of adding comments please add the information (including the above) to your question. – markdrayton Sep 6 '09 at 19:24

You need to have a RewriteCond for the HTTP_HOST

the RewriteRule's are applied to the URL path only!

share|improve this answer
I disagree. I have this already, which helps to properly map the hostname to a directory. RewriteCond %{HTTP_HOST} ^[^.]+\$ RewriteRule ^(.+) %{HTTP_HOST}$1 [C] The problem I'm having is almost the opposite one. Conceptually I want to undo the rewrite rules when a specific path is passed after the host name. – Tony G. Sep 6 '09 at 19:23

Try this:

RewriteCond    %{HTTP_HOST}    ^$
RewriteRule*)$1 [P]
share|improve this answer
When I try this, the mod_rewrite works, mapping to via proxy, but I get 403 FORBIDDEN in the browser, which I do not get when I go directly to – Tony G. Sep 6 '09 at 18:54
k, I got it. I had to modify my mod_proxy settings to allow from localhost. Now I no longer get the 403 FORBIDDEN and the site loads properly (with broken links of course, but that can be fixed with more rewrite rules I think) – Tony G. Sep 6 '09 at 19:47

Your Answer


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