Results 1 to 10 of 10

Thread: serveralias not working in apache2

  1. #1
    Join Date
    May 2006
    Beans
    14

    Question serveralias not working in apache2

    Hi. Webserver working great if I type in www.example.com. If I type in example.com all I get is a web page that says "It Works". So my 'serveralias' doesn't seem to work. Here's my www.example.com file:

    Code:
    <VirtualHost *>
            ServerAdmin admin@example.com
            ServerName  www.example.com
            ServerAlias example.com
    
            # Indexes + Directory Root.
            DirectoryIndex index.php
            DocumentRoot /var/www/www.example.com/
    
    </VirtualHost>
    Any thoughts? Thanks!

  2. #2
    Join Date
    Nov 2005
    Location
    NEK Vermont
    Beans
    Hidden!
    Distro
    Ubuntu UNR

    Re: serveralias not working in apache2

    DocumentRoot is pionting to /var/www which contains the index.html apache2 is looking for.
    My understanding of the ServerAlias directive is that it allows path names to be appended to the virtual host file. For example if "localhost" in the address bar brings up the default page, then "localhost/example.com" should bring up the page you are trying to see...assuming you have localhost as a ServerName in httpd.conf

    EDIT: the above is probably not correct. You still would need the appropriate .html in /var/www. It seems like what you want is a redirect.
    Last edited by spiderbatdad; May 20th, 2008 at 03:29 AM.

  3. #3
    Join Date
    May 2006
    Beans
    14

    Re: serveralias not working in apache2

    how would I redirect? here's the real url's:

    http://www.bretography.com

    http://bretography.com

  4. #4
    Join Date
    May 2007
    Location
    Phoenix, Arizona USA
    Beans
    2,909
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: serveralias not working in apache2

    Quote Originally Posted by roderashe View Post
    Hi. Webserver working great if I type in www.example.com. If I type in example.com all I get is a web page that says "It Works". So my 'serveralias' doesn't seem to work. Here's my www.example.com file:

    Code:
    <VirtualHost *>
            ServerAdmin admin@example.com
            ServerName  www.example.com
            ServerAlias example.com
    
            # Indexes + Directory Root.
            DirectoryIndex index.php
            DocumentRoot /var/www/www.example.com/
    
    </VirtualHost>
    Any thoughts? Thanks!
    Try this:

    Code:
    <VirtualHost *>
            ServerAdmin admin@example.com
            ServerName  www.example.com
            ServerAlias *example.com
    
            # Indexes + Directory Root.
            DirectoryIndex index.php
            DocumentRoot /var/www/www.example.com/
    
    </VirtualHost>
    -Tim
    www.pcchopshop.net

    Hard to find and obsolete PC and server parts. "If we can't find it, it probably doesn't exist"

  5. #5
    Join Date
    Jan 2006
    Location
    United Kingdom
    Beans
    2,787
    Distro
    Kubuntu 6.06 Dapper

    Re: serveralias not working in apache2

    Have you turned name-based virtual hosting on?

    i.e. NameVirtualHost *

    (it needs to go outside of any <Virtualhost> container, e.g. the line above in your posed config)

    Mathew
    www.NewtonNet.co.uk - Now supporting IPv6!

    ~ Please don't use PM's to request assistance - post your query on the forum and share the discussion - if you've got a problem chances are you won't be the only one! ~

  6. #6
    Join Date
    May 2007
    Location
    Phoenix, Arizona USA
    Beans
    2,909
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: serveralias not working in apache2

    MJN is correct here, you must turn on named based vitual hosting.

    Also, your alias line should be

    ServerAlias *.example.com

    Notice the dot. My bad, sorry.

    -Tim
    www.pcchopshop.net

    Hard to find and obsolete PC and server parts. "If we can't find it, it probably doesn't exist"

  7. #7
    Join Date
    Jan 2006
    Location
    United Kingdom
    Beans
    2,787
    Distro
    Kubuntu 6.06 Dapper

    Re: serveralias not working in apache2

    Unless sub-domain matching is required, ServerAlias example.com will match example.com as it stands.

    Mathew
    www.NewtonNet.co.uk - Now supporting IPv6!

    ~ Please don't use PM's to request assistance - post your query on the forum and share the discussion - if you've got a problem chances are you won't be the only one! ~

  8. #8
    Join Date
    May 2007
    Location
    Phoenix, Arizona USA
    Beans
    2,909
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: serveralias not working in apache2

    Quote Originally Posted by MJN View Post
    Unless sub-domain matching is required, ServerAlias example.com will match example.com as it stands.

    Mathew
    You are absolutely correct, however, if he wants to reach the site using http://example.com or www.example.com he will need the wild card for sub-domain matching.

    -Tim
    www.pcchopshop.net

    Hard to find and obsolete PC and server parts. "If we can't find it, it probably doesn't exist"

  9. #9
    Join Date
    Jan 2006
    Location
    United Kingdom
    Beans
    2,787
    Distro
    Kubuntu 6.06 Dapper

    Re: serveralias not working in apache2

    The ServerName directive takes care of that - there is no need to duplicate it in the ServerAlias.

    Not that it matters (assuming the OP wants all sub-domain matching, not just www.) - I was just pointing out that in this particular case the ServerName and ServerAlias directives are already configured correctly for the situation.

    Mathew
    www.NewtonNet.co.uk - Now supporting IPv6!

    ~ Please don't use PM's to request assistance - post your query on the forum and share the discussion - if you've got a problem chances are you won't be the only one! ~

  10. #10
    Join Date
    May 2006
    Beans
    14

    Re: serveralias not working in apache2

    Thanks, everyone. Turns out there was an erroneous ip address in my DNS zone file. Works fine now. Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •