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>
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.