Apache2 Name Virtual host

Posted on 2005-05-12
Last Modified: 2008-01-09
 I have an Apache2 web server on Debian.

I have two sites pointing to the same ip: and

The is the webmail and runs using SSL certs.

My question is, how do I configure these Virtual hosts so that when I type into my browser it opens the secure webmail, but if I type it direct me to the default web page.

Thanks for your time

Question by:PastorDwayne
    LVL 5

    Expert Comment

    Not sure how to achieve what you describe using a single IP (since you can't specify a port in DNS), but can suggest a more common alternative:

    In DNS, point to your web server's IP.  On that site provide a page that redirects the user to https://your_webmail_virtual_host.  If you're running your secure webmail site on a non-standard port, say port 8088, your redirect would be to http://your_webmail_virtual_host:8088.
    LVL 1

    Expert Comment

    apache does support NameBasedVirtualHost that is you can have more that one websites for an IP I hope you already knew that. The default can be configured without any issues right. for the second put a php file or some thing that will redirect the request to You can also use apache's mod_rewrite to achive this but using php will be easier.

    LVL 3

    Accepted Solution

    Here's the Apache configuration to do what you want. I do something very similar on one of my sites. I'm assuming you already have the two sites working separately and can plug in the appropriate config (and change the names and IP address, of course):



    # The first entry is the default if ServerName doesn't match
        ServerName mycompany   # used for display only
        DocumentRoot /www/mycompany
        # ... more directives for regular web page

        ServerName email
        ServerAlias email.*
        Redirect permanent / "https:/"

       SSLEngine on
       DocumentRoot /www/secure_webmail
      # ... more directives for secure webmail

    I have no reason to think that doing this with PHP would be easier or more efficient. Note that if someone types a URL such as it will be redirected to If you'd rather have all URLs in the domain get redirected to then change the redirect directive to:

       RedirectMatch permanent .* "https:/"

    Hope this helps,


    Author Comment


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
    Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now