Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have this in my vhost file which direct all sub domains which do not exist to the main www.

<VirtualHost *:80>
    ServerName mysite.com
    ServerAlias *.mysite.com
    Redirect 301 / http://www.mysite.com/
</VirtualHost> 

The problem I have at the moment is that some people are linking to my website with www.mysite.com. notice the . at the end. This is causing the CMS to break.

Is there a way to modify this ServerAlias or an alternative way so that this has a wild card at the end? I tried adding a * but this didn't work.

This is the full vhost for this domain:

# DEV
<VirtualHost *:80>
    ServerName dev.mysite.com
    DocumentRoot /var/www/mysite.com/subdomain/dev/public

    ErrorLog /var/log/apache2/mysite.com-error.log
    LogLevel warn
    CustomLog /var/log/apache2/mysite.com-access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerName www.mysite.com
    DocumentRoot /var/www/mysite.com/public

    <Directory /var/www/mysite.com/public>
        Options +FollowSymlinks
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]

        ErrorDocument 404 index.php
    </Directory>
    <Directory /var/www/mysite.com/public/webapp>
        RewriteEngine Off
        <Files *>
            order allow,deny
            deny from all
        </Files>
        <FilesMatch "\.(png|gif|jpe?g|css|js|swf|flv|htc|eot|woff|ttf|svg)$">
            order allow,deny
            allow from all
        </FilesMatch>
    </Directory>
    <Directory /var/www/mysite.com/public/webapp/shared>
        <Files *>
            order allow,deny
            allow from all
        </Files>
    </Directory>

    ErrorLog /var/log/apache2/mysite.com-error.log
    LogLevel warn
    CustomLog /var/log/apache2/mysite.com-access.log combined
</VirtualHost>

# Redirect for non existent subdomains
<VirtualHost *:80>
    ServerName mysite.com
    ServerAlias *.mysite.com
    Redirect 301 / http://www.mysite.com/
</VirtualHost>

I have disabled .htaccess thats the reason for all the <Directory>

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If this vhost is the first one, you do not need ServerAliases.

The first-listed vhost will by definition receive all requests that do not match a specific virtualhost's ServerName.

Remove the ServerAlias and make sure this vhost is loaded first.

share|improve this answer
    
Sadly no this is the last vhost for this domain. I quickly tested as you suggested by removing the other vhost and get the same problem. –  John Magnolia Apr 10 '12 at 14:48
    
...so order it to make it the first. –  adaptr Apr 10 '12 at 14:50

Your Answer

 
discard

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.