简体   繁体   中英

Using Apache mod_proxy to reverse proxy and change url

I am successfully using Apache mod_proxy to reverse proxy a request to testing.com/foo/bar to mybackendservice.com/foo. However, instead of the current url which is shown in the browser : testing.com/foo/bar, I would like to have the url reflect testing.com/foo. How can I achieve this? My mod proxy setup looks something like:

ProxyPass /foo/bar mybackendservice.com/foo
ProxyPassReverse /foo/bar mybackendservice.com/foo

I did also try rewriting the url using:

RewriteEngine on

RewriteRule foo/bar foo [NC]

but this doesn't seeem to work. Is there another way of achieving this?

You need to use HTTP redirects instead of mod_rewrite.

Create a script which returns HTTP status 302 Found and specify HTTP Header Location: /foo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM