Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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


<VirtualHost *:80>
        DirectoryIndex index.php
        <If "%{SERVER_PROTOCOL} != 'HTTPS'">
            Redirect /

Save, and then restart:

sudo /etc/init.d/apache2 restart
Syntax error on line 4 of /etc/apache2/sites-enabled/000-default:
Invalid command '<If', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.!
share|improve this question
up vote 4 down vote accepted

"If" is not something Apache understands (before version 2.3). You probably should look at mod_rewrite

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*)$1 [R,L]
share|improve this answer
Are you sure? The documentation says otherwise, it even suggests using it over Rewrite: – NotGaeL Dec 14 '11 at 18:29
<If> is from apache2.3. I suspect you are using 2.2. – Mark Wagner Dec 14 '11 at 18:34
You're right, I'm dumb. Thanks :) – NotGaeL Dec 14 '11 at 18:40
Done. Although I believe != is completely valid. I'll have to double-check. – TheCompWiz Dec 14 '11 at 19:15
reverted back. :D – TheCompWiz Dec 14 '11 at 19:21

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.