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!
link|improve this question

feedback

1 Answer

up vote 1 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]
link|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
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.