Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

<Directory "/var/www/example/public/admin/view/javascript/ckeditor">
        AddType application/x-javascript .js
        AddType text/css .css
        AddType text/xml .xml

    ErrorLog /var/log/apache2/example-error.log
    LogLevel warn
    CustomLog /var/log/apache2/example-access.log combined

    # Redirect for all non existent subdomains
    <VirtualHost *:80>
        ServerAlias *
        Redirect 301 /
share|improve this question
up vote 3 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


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.