How to route two different paths to the same serve

2019-07-26 19:16发布

问题:

Consider two urls:

  1. www.mysite.com/*
  2. www.mysite.com/browse/*

The backend runs at http://localhost:8080

How can I make sure that all requests with following pattern will end up at my backend like below?

Example:

www.mysite.com/doA --> localhost:8080/doA

www.mysite.com/browse/doA --> localhost:8080/doA

So basically both www.mysite.com/doA and www.mysite.com/browse/doA result in the same thing.

I want to use apache server. I can redirect one using proxy_http. But it doesn't work for two or more urls:

This is my config that work for one url

<VirtualHost *:80>
  ProxyPass         /  http://localhost:8080/
  ProxyPassReverse  /  http://localhost:8080/
  ProxyRequests     Off
  <Proxy http://localhost:8080/*>
    Order deny,allow
    Allow from all
  </Proxy>
</VirtualHost>  

回答1:

This should work:

<VirtualHost *:80>
ServerName example.com
ProxyRequests     Off
ProxyPass         /browse/ http://localhost:8080/
ProxyPass         /        http://localhost:8080/
ProxyPassReverse  /        http://localhost:8080/
</VirtualHost>

The configured ProxyPass and ProxyPassMatch rules are checked in the order of configuration. The first rule that matches wins. So usually you should sort conflicting ProxyPass rules starting with the longest URLs first. Otherwise, later rules for longer URLS will be hidden by any earlier rule which uses a leading substring of the URL