Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have few different vhost created and every one has its own folder in /var/www/ like this


Now, when I type url with www it points to the /var/www/example1/index.html so that's working fine, but when I type without www it points to /var/www/ and I can see all the folders, I don't have index.html in /var/www/.

I looked here and created .htaccess in /var/www/:

    RewriteEngine On
    RewriteBase /
    RewriteCond % ^ [NC]
    RewriteRule ^(.*)$$1 [L,R=301]

but it's not working.

This is how the all vhosts look like:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName *example1*
        ServerAlias *.*example1*
        DocumentRoot /var/www/example1
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        <Directory /var/www/example1/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None

I have cleared browser cache. Any idea how to fix this?

share|improve this question
up vote 3 down vote accepted

The ServerName directive doesn't take wildcards, that's what ServerAlias is for. From the manual

ServerName [scheme://]fully-qualified-domain-name[:port]

so you should do something like

ServerAlias *.*example1*.com
share|improve this answer
This worked, tnx – cikatomo Feb 17 '13 at 18:19

You can place following code Apache’s httpd.conf vhost section or in .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$$1 [R=permanent,L] 
share|improve this answer
still not working,the ServerName in vhost was the problem. – cikatomo Feb 17 '13 at 18:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.