I have one server on example.com, and I have another one on example.com:10001.
When users try to reach example.com:10001 they end up on example.com:10001/index.php/login and that's how it should be.

Is there a rewrite rule, to hide the 10001 port so it looks like example.com/index.php/login?

  • 2
    You can't 'hide' the port unless the content is reachable on http or https (port 80 or port 443). There's always a port being used, just the defaults of 80 (for http) and 443 (for https) aren't displayed. You can't pretend 10001 isn't 10001. mod_rewrite changes where the browser goes to, not just what the browser displays in the address bar. – yoonix Jan 17 '19 at 18:17

The details from this comment suggests that example.com A is pointed to a public IP and the servers are behind a NAT with port forwarding to the two servers:

The problem is that the site using the port 10001 is hosted by another server. The example.com is and the example.com:10001 is

You could have

  • a reverse proxy at your, proxying queries to As the server is Apache 2.4, the correct documentation is: Apache Module mod_proxy.

  • a new proxy server listening to external example.com:80 with reverse proxies to both and (or whatever the internal port of this other server is). Nginx would be an efficient alternative for this. Documentation: NGINX Reverse Proxy.

With both cases the reverse proxy needs to be configured either as a subfolder or a subdomain.


The short answer is no. The browser is what's hiding the port from users; when you use http, it automatically assumes port 80 and when you use https it assumes port 443, hiding these ports from the user. Using any nonstandard port, most browsers would show the port as part of the address.

If I'm understanding your issue properly, there are a few ways to host multiple sites on the same IP, however. Instead of using a different port, you could use a subdomain (myothersite.example.com), or you could use a path below example.com such as example.com/mysite2.

  • You are right I'd like to host multiple sites. The problem is that the site using the port 10001 is hosted by another server. The example.com is and the example.com:10001 is – Mrwut Jan 17 '19 at 18:39
  • 2
    @Mrwut in that case you can look into proxying, i.e. sending the requests onward to another server. – Halfgaar Jan 17 '19 at 19:51
  • 1
    If the two sites are on the same hostname, but different IP addresses, then that sounds like he's probably already doing some form of proxying. – Dave Sherohman Jan 19 '19 at 9:48

If I understand your question you can accomplish this using the [P] flag of mod_rewrite:

RewriteRule "/(.*)" http://example.com":10001/$1" [P]

There are additional considerations and you should probably use mod_proxy directly.

  • 1
    Although the OP currently has two different sites on the same hostname/URL (distinguished by the port). So they are going to have to first create a different host/subdomain/subdirectory in order to distinguish requests for the two sites. – MrWhite Jan 19 '19 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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