I know there are a number of different ways to redirect using apache although I wanted to check if this is the correct way of doing it via virtual host?
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/public
<Directory "/var/www/example/public">
Options +FollowSymlinks
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
</Directory>
<Directory "/var/www/example/public/admin/view/javascript/ckeditor">
AddType application/x-javascript .js
AddType text/css .css
AddType text/xml .xml
</Directory>
ErrorLog /var/log/apache2/example-error.log
LogLevel warn
CustomLog /var/log/apache2/example-access.log combined
</VirtualHost>
# Redirect for all non existent subdomains
<VirtualHost *:80>
ServerAlias *.example.com
Redirect 301 / http://www.example.com
</VirtualHost>
I'd use the textual argument
permanent
instead of the numerical status301
forRedirect
(or useRedirectPermanent
in the first place). But that's just cosmetics.Otherwise your configuration for redirecting any subdomain !=
www
to your canonical URL is just fine.