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 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>
share|improve this question

1 Answer 1

up vote 2 down vote accepted

I'd use the textual argument permanent instead of the numerical status 301 for Redirect (or use RedirectPermanent in the first place). But that's just cosmetics.

Otherwise your configuration for redirecting any subdomain != www to your canonical URL is just fine.

share|improve this answer

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.