here is my /etc/httpd/conf.d/test.conf

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName test.dev
    ServerAlias test.dev.*.xip.io
    DocumentRoot /var/www/html/user/test/web
    ErrorLog "/var/www/html/user/test/app/logs/httpd_error.log"
    CustomLog "/var/www/html/user/test/app/logs/httpd_access.log" combined
    <Directory "/var/www/html/user/test/web">
        # AllowOverride All      # Deprecated
        # Order Allow,Deny       # Deprecated
        # Options All
        # Allow from all         # Deprecated
        # Require all granted    # << New way of doing it
        Options +FollowSymlinks +Indexes
        AllowOverride all

Accessing http://test.dev. successfully redirects me to the proper website. Accessing also redirects me to the same website instead of the index that I was expecting to see. Also, accessing http://test.dev-some-random-string. will also redirect me to the same website.

How do I configure this so when I try to access test.dev., I will end up in page I am coding while accessing will show me the home page.

I am currently using a centos 6 running in a virtual box with a bridged adapter for the network. Here is my /etc/httpd/conf/httpd.conf.



If you define only one virtual host, then all requests to httpd will be served by that virtual host, whether or not they match the ServerName or ServerAlias, because the first virtual host is also the default virtual host. Search for "default virtual host" in the Apache "Name-based Virtual Host Support" documentation.

Note also that once you define any virtual hosts, the default ServerName goes away, and you have to define a new vhost to recreate it if you still want to use it. See the inset "Main host goes away" at the above link.

So, try defining a default virtual host, which can be as simple as

<VirtualHost *:80>
    DocumentRoot /var/www/html

and make sure it comes before all of your other virtual hosts in the configuration. Then any requests that don't match the other virtual hosts will be served by that one.

| improve this answer | |
  • I thought the /etc/conf/httpd.conf is supposed to be the "default" – kapitanluffy Jun 7 '15 at 9:04
  • See the added 2nd paragraph above, about "Main host goes away". – Andrew Schulman Jun 7 '15 at 9:20

You need to define a VirtualHost for every web page that you want to show; even if is the main one, you also need to define a VirtualHost where define "ServerAlias". If there's only one VirtualHost, you will be redirected always to the site defined in ServerAlias.

| improve this answer | |
  • 1
    A virtual host for every web page? – Andrew Schulman Jun 7 '15 at 8:32
  • If you want to set only a URL, you don't need to configure VirtualHosts. As soon you as you want to host two web sites on the same IP/host, if you only configure only one VirtualHost, Apache will redirect you to that site. So, for the first site, you need to configure also a VirtualHost with the ServerAlias as the URL of the first site. – Paco Bernabé Pellicer Jun 7 '15 at 10:31

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.