-2

I have this vhost configuration, but the 'Redirect' part does not seems to work. Is it wrong ?

<VirtualHost *:80>
    ServerAlias in.example.com
    ProxyRequests Off
    ProxyVia Off
    ProxyPass / http://127.0.0.1:9091/
    ProxyPassReverse / http://127.0.0.1:9091/
    Redirect permanent / http://in.example.com/web/
</VirtualHost>
Nison Maël
  • 119
  • 6
  • What does 'does not seem to be working' mean ? What were you expecting and what is actually happening? If there are error messages what are they? Is there anything interesting in the logs? – user9517 Oct 21 '12 at 07:24

2 Answers2

1

It's possible that mod_alias may not be loaded, as it provides redirect. However, then, you would expect configuration errors in the log.

It's also possible that your ProxyPass and ProxyPassReverse directives are taking precedence. If you intend to redirect, you should either put the rule on the proxied server, or remove the proxy directives. The proxy will pass the 301 redirect.

Additionally, if you redirect / to a subdirectory of itself, you will create a redirect loop. From the docs: any request beginning with URL-path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-path will be appended to the target URL. This means that when the browser follows up with a request for /web/, it will get a redirect to http://in.example.com/web/web/, and so forth. Consider using RedirectMatch with an anchored regex instead. If by not working you mean that the browser complains of a redirect loop, this is the answer.

Falcon Momot
  • 25,244
  • 15
  • 63
  • 92
1

You can't ProxyPass / and redirect /. I guess what you're looking to do is ProxyPass all requests to your local app and if that returns a 404 Not Found then redirect them elsewhere.

Unfortunately, if your app on 127.0.0.1:9091 returns a 404 then this will be returned to your client.

Instead, you need to "un-proxy" the paths that your app will serve. You can do this two ways:

  1. Create ProxyPass rules just for known paths:

For example:

ProxyPass /myapp http://localhost:9091

2. Create exclusions:

For example:

ProxyPass / http://localhost:9091
ProxyPass /notmyapp !
ProxyPass /images !

This will make /notmyapp and /images to be passed through to the redirect

Alastair McCormack
  • 2,184
  • 1
  • 15
  • 22
  • Exactly what I needed (except that I had to use "ProxyPassMatch ^/$ !" followed by "RedirectMatch ^/$ http://www.myserver.com/web/") – Nison Maël Oct 21 '12 at 20:24