Apache defaulting to first virtualhost conf file in folder

Discussion in 'Server Operation' started by sfunk1x, Nov 23, 2009.

  1. sfunk1x

    sfunk1x New Member

    Apache defaulting to last created virtualhost conf file in folder

    Hey all -

    I've got a CentOS 5.2 server running Apache 2 and a menagerie of other packages. I'll try to make this quick:

    - Server running Apache configured to load a variety of virtualhost configuration file in a /etc/httpd/conf/vhost folder. It loads all the virtual host files just fine and all the websites appear (subdomains and otherwise).

    Main issue:

    If a user browses something like 'nodomainexists.domainname.com' into a browser url bar, you're taken to the site whose vhost file was created last. I would much rather have users who attempt to use invalid subdomains to be forwarded to a specific virtualhost file (that runs the main website/frontend). How would I go about making sure that all non-existant subdomains get routed to a specific virtualhost?

    For example:

    last.domain.com exists (vhost file was created last)
    not.domain.com doesn't exist (no vhost file, etc)
    www.domain.com does exist (has vhost file, valid site)

    When a user goes to not.domain.com, they'll get last.domain.com instead of being sent to www.domain.com.

    How would I go about making the www.domain.com a catch all for bad and/or misspelled subdomains?

    Thanks in advance!
     
    Last edited: Nov 24, 2009
  2. falko

    falko Super Moderator Howtoforge Staff

    Make sure that the ServerName/ServerAlias directives in your vhosts just list the domains/hostnames that the vhosts should listen to, and then create a default vhost in your Apache configuration before all other vhosts.
     

Share This Page