# Apache22 mod_rewrite



## awanseti (May 7, 2015)

I set up FreeBSD for ProxyIn Server (ex : 192.168.10.10)

I have config like this:


```
ProxyPass /aaa http://192.168.10.11/aaa
ProxyPassReverse /aaa http://192.168.10.11/aaa
  
ProxyPass /bbb http://192.168.10.11/bbb
ProxyPassReverse /bbb http://192.168.10.11/bbb


<IfModule mod_proxy.c>
  <IfModule mod_rewrite.c>
    RewriteEngine On
   
    RewriteCond  %{HTTP_HOST} test.mydomain.com
    RewriteRule ^/ccc(.*) http://192.168.10.11/ccc/$1
    RewriteRule ^/ddd(.*) http://192.168.10.11/ddd/$1
    RewriteRule ^/eee(.*) http://192.168.10.11/eee/$1
    RewriteRule  ^/(.*) http://192.168.10.11/test/$1

  </IfModule>
</IfModule>
```

My purpose is I wanna want to test.mydomain.com to go to http://192.168.10.11/test/ page without changing the domain and when asked test.mydomain.com/ccc/ go to http://192.168.10.11/ccc/ page without changing the domain.

When I use that configuration my purpose is accomplished but, my configuration with proxypass is disturbed.

My URL access now:
test.mydomain.com >> OK
test.mydomain.com/ccc >> OK
test.mydomain.com/ddd >> OK
test.mydomain.com/eee >> OK
192.168.10.10/aaa >> error The requested URL /test/aaa/ was not found on this server.
192.168.10.10/bbb >> error The requested URL /test/bbb/ was not found on this server.

But when my configuration with bold text that I added before is deleted the proxypass configuration is running well:

My URL access when bold text configuration is deleted:
test.mydomain.com >> OK
192.168.10.10/aaa >> OK
192.168.10.10/bbb >> OK

Can you help me what configuration that can be solve my problem so all my URLs are okay?
test.mydomain.com >> OK (using mod_rewrite)
test.mydomain.com/ccc >> OK (using mod_rewrite)
test.mydomain.com/ddd >> OK (using mod_rewrite)
test.mydomain.com/eee >> OK (using mod_rewrite)
192.168.10.10/aaa >> OK (using proxypass)
192.168.10.10/bbb >> OK (using proxypass)

I need your advice.


----------



## junovitch@ (May 10, 2015)

I'm not a big Apache person but know there are a few on the Forums.  The list of stuff to avoid makes a mention that RewriteRule applies before ProxyPass so that would explain the issue.


> You may need to use RewriteRule instead when there are other RewriteRules in effect in the same scope, as a RewriteRule will usually take effect before a ProxyPass, and so may preempt what you're trying to accomplish.


http://httpd.apache.org/docs/2.2/rewrite/avoid.html

Would a redirect be an acceptable work around?  Just redirect any requests explicitly for the root of the site for the /test/ URI.

```
Redirect / http://www.example.com/test/
```


----------

