Looking for some advice on the following:

I'm wanting to have two servers with same domain. Not looking to have subdomains.

Domain: https://example.com

Server A: https://example.com/games/abcs13343/results

Server B: https://example.com/blogs/games-blog-3

Is this achievable through doing a proxy reverse on Server A or is there a better way of doing something like this without subdomains?

  • 4
    You cannot have two servers with the same domain name without very special tricks. You can proxy a path from Server A to Server B very easily. Server B would be represent a sub portion of the domain name space but would not have a different server name (usually an IP address or localhost). Nov 15, 2023 at 1:30
  • @JohnHanley - That what it would be, Server B would just be an IP address for the time being. So would it have to be a proxy from Server A to Server B?
    – YaBCK
    Nov 15, 2023 at 14:11
  • The following question can give you a hint on how to do it: serverfault.com/questions/429122/… Nov 15, 2023 at 16:15
  • @LuisAlbertoBarandiaran - Would this work if the /blogs isn't an actual sub directory on the server and is just a route in the web application?
    – YaBCK
    Nov 16, 2023 at 12:32
  • yes it should work. You can have /blogs point to a different server, or even a different port inside your own server, using Apache as the proxy Nov 16, 2023 at 19:48

2 Answers 2


Let's say you have your 2 servers, Server A and Server B with IP_A, IP_B respectively.

The HTTP/HTTPS requests come through ports and using a basic router only ports can be forwarded to each of your 2 local server IPs.

You can use 1 of your 2 servers to act as a proxy to the other server.

Firstly forward port 80 & 443 to the server A using its ip IPA.

Let the server with ip IPA, channel the requests to the other server(s) based on the requested URL.

Depending on what Server Software you use you need to follow different approaches.

In apache for port 80 you will need to edit your configuration file:

sudo gedit /etc/apache2/sites-available/000-default.conf

Add the lines at the end of <VirtualHost *.80>

<VirtualHost *.80>


RewriteRule ^/games/?(.*)$ http://{IPB}/games/$1 [P,L] 
ProxyPassReverse /games http://{IPB}/games

RewriteRule ^/blogs/?(.*)$ http://{IPB}/blogs/$1 [P,L] 
ProxyPassReverse /blogs http://{IPB}/blogs


In each case, we added the ProxyPassReverse directive to ensure that any redirects issued by the backend are correctly passed on to the client.


Is this achievable through doing a proxy reverse on Server A or is there a better way of doing something like this without subdomains?

Yes - this is a very common use case for a reverse proxy server.

I disagree slightly with @Thanasis answer) in as much as the ideal way to do this with Apache is NOT RewriteRules, rather it is ProxyPass rules. (Indeed this is the whole purpose of mod_proxy in Apache).

The idea is in your Virtualhost to ensure mod_proxy is enabled (eg with a2enmod proxy to enable this) and then add

ProxyPass "/blogs" "https://serverb.domain"
ProxyPassReverse "/blogs" "https://serverb.domain"

If this is "to much", you can always look at using someone like Cloudflare to do it for you.

  • Use of the [P] flag ( my RewriteRule) causes the request to be handled by mod_proxy, and handled via a proxy request. The advantage in using mod_rewrite is that you get more control for mapping requests. But you are right somewhere in the apache documentation ( httpd.apache.org/docs/2.4/rewrite/flags.html#flag_p )it states that it is better to use ProxyPass directly as it handles better the persistent connections.
    – Thanasis
    Nov 27, 2023 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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