Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to use mod_rewrite in conjunction with mod_proxy to deliver contents from a different internal webserver ( through a (fake) subdirectory "foo" (

Using mod_proxy with ProxyPass directive I was able to do this already with this configuration in /etc/apache2/mods-enabled/proxy.conf

ProxyPass /foo
ProxyPassReverse /foo

Now I have the additional requirement to enforce rewriting all requests to dynamic resources from to https://, which again standalone works as well, but not together with the ProxyPass rules stated above. It seems the proxy configuration has always precedence over the rewrite rules.

As as far as my research has shown me utilizing mod_proxy from within my rewrite rules should be as easy as adding

RewriteCond %{REQUEST_URI} ^/foo RewriteRule ^/foo(.*)$1 [P]

to my rewrite rules and the rewritten URI will be automatically passed through mod_proxy. I turned on RewriteLog with a LogLevel of 9, but I am not able to see the matching of ^/foo and execution of the following Proxy-RewriteRule afterwards. There is nothing like go-ahead proxy, or any mention of proxying, not even an error entry within the RewriteLog.

I have the following proxy modules activated in my apache2 configuration


I tried to test my RewriteCondition with another example - this time matching ^/foo and redirecting to

RewriteCond %{REQUEST_URI} ^/foo
RewriteRule ^(.*)$ [R=302,L]

which is working as intended, with the following results in the RewriteLog:

RewriteCond: input='/foo' pattern='^/foo' => matched rewrite 'foo' -> '' explicitly forcing redirect with escaping for redirect redirect to [REDIRECT/302]

Following below is the rewrite configuraiton I am using within a directory section of my vhost.

    <Directory /my/app/webroot >
            RewriteEngine On
            RewriteBase /

            #redirect all http requests to https - WORKING
            # incoming request was forwarded as http from ELB
            RewriteCond %{HTTP:X-Forwarded-Proto} =http
            # avoid https rewriting for static files like images, javascripts, files and templates
            # for folders /img, /js, /css, /files and /templates under webroot
            RewriteCond %{REQUEST_URI} !^/(img|js|css|files|templates)
            RewriteRule (.*) https://{REQUEST_URI}  [R=301,L]

            # requests to /foo *should* be handled by mod_proxy - NOT WORKING
            RewriteCond %{REQUEST_URI} ^/foo
            RewriteRule ^/foo(.*)$1 [P]

            #pretty URLS for web-application - WORKING
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

The machine in question is a basic debian server installation, with apache2 and php and is hosted in the amazon cloud behind a Elastic Load Balancer.

If you read down this far - first of all - thank you for patience!

It would be great if somebody could help with resolving this problem. Maybe it is just a little think I've overseen.

Many thanks in advance!

share|improve this question

1 Answer 1

up vote 0 down vote accepted


RewriteRule ^/foo(.*)$1 [P]


RewriteRule ^foo(.*)$$1 [P,L]

Will be a problem, write to email.

share|improve this answer
This solved the problem indeed! Thank you very much for your quick response! – chris_W Jan 31 '11 at 17:17
You are welcome) – alvosu Jan 31 '11 at 17:18

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.