Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a single IP address say

I want my VM to use a certain port whenever a specific URL is used, but without having to specify the port.

So instead of saying I'd like to say (to hit the docroot) and for the port to be implied. How can I do this with Apache 2?

<VirtualHost *:8200>
        DocumentRoot /var/www/html-8200/
        AllowEncodedSlashes On    
        RewriteEngine on
        RewriteOptions Inherit
</VirtualHost> =>

share|improve this question
Where do you want to "say" - in your ServerName directive, or a connecting client browser? – Shane Madden Oct 26 '11 at 21:03
on the client -- internal network -- the URL isnt public exposed – qodeninja Oct 26 '11 at 21:05
up vote 2 down vote accepted

Sorry, not possible.

The port that a client connects to is determined by the client, not the server - Apache has no ability to change this behavior in a client browser. Port 80 is always the implied port for http://, and port 443 is always the implied port for https://.

You could 30x redirect the client to :8200, or reverse proxy connections from 80 to 8200.. but those approaches would probably be pointless, depending on what you're trying to accomplish.

share|improve this answer
Are you sure about that? The client may pick a port but Apache can proxy forward any request, even from a directory to a new domain. – qodeninja Oct 26 '11 at 21:26
Yes, I mentioned that option: or reverse proxy connections from 80 to 8200 - but you'd still need a port 80 listener, so what would be the point of that? What are you trying to accomplish? – Shane Madden Oct 26 '11 at 21:27
If your end goal is to make the address easier to remember for users (for example, an application you're running requires that it run on port 8200) wouldn't it be easiest to do as Shane suggested and just have it redirect to when the user goes to Or are you concerned about whether the user can see the ":8200" in the address? If you can provide the "Why" to this whole process, it might help out to find the best solution. – Safado Oct 26 '11 at 22:08

You could use mod_alias or mod_proxy and setup something like:

which apache would point to a different docroot

Alias /somepath "/usr/local/www/somepath"

while would still point to the usual docroot

or, if the service running on port 8200 is not apache, but some other service, that again, you want to access on the default port, you can use mod_proxy to reverse proxy the requests from port 80 to 8200

If you want the same domain to point to something different only from your machine (for example, you want to test the development codebase of your website, but on the real domain), the only real choice is to setup the second version of the site on a different IP address, and then use the local hosts file on the client machine, to misdirect the domain name of the second ip address.

share|improve this answer
+1 your feedback was helpful thank you! – qodeninja Oct 27 '11 at 17:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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