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.

Why??

<VirtualHost *:80>
        ServerAdmin admin@mydomain.com
        DirectoryIndex index.php
        <If "%{SERVER_PROTOCOL} != 'HTTPS'">
            Redirect / https://www.mydomain.com:443/
        </If>
.....
</VirtualHost>

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.
   ...fail!
share|improve this question
add comment

1 Answer

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 ^/(.*) https://www.mydomain.com:443/$1 [R,L]
share|improve this answer
    
Are you sure? The documentation says otherwise, it even suggests using it over Rewrite: httpd.apache.org/docs/2.3/rewrite/remapping.html#canonicalhost –  elcodedocle Dec 14 '11 at 18:29
3  
<If> is from apache2.3. I suspect you are using 2.2. httpd.apache.org/docs/2.2/rewrite/remapping.html#canonicalhost –  Mark Wagner Dec 14 '11 at 18:34
    
You're right, I'm dumb. Thanks :) –  elcodedocle Dec 14 '11 at 18:40
1  
Done. Although I believe != is completely valid. I'll have to double-check. –  TheCompWiz Dec 14 '11 at 19:15
1  
reverted back. :D –  TheCompWiz Dec 14 '11 at 19:21
show 2 more comments

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.