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 mydev.net:8200 I'd like to say mydev.net (to hit the docroot) and for the port to be implied. How can I do this with Apache 2?

<VirtualHost *:8200>
        ServerAdmin me@mydev.net
        DocumentRoot /var/www/html-8200/
        ServerName mydev.net
        ServerAlias www.mydev.net
        AllowEncodedSlashes On    
        RewriteEngine on
        RewriteOptions Inherit

http://mydev.net => http://mydev.net:8200

  • Where do you want to "say" mydev.net - 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

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.

  • 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. httpd.apache.org/docs/2.0/mod/mod_proxy.html – qodeninja Oct 26 '11 at 21:26
  • 1
    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
  • 1
    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 mydev.net:8200 when the user goes to mydev.net? 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 http://mydev.net 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.

  • +1 your feedback was helpful thank you! – qodeninja Oct 27 '11 at 17:41

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.