8

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!
NotGaeL
  • 277
  • 1
  • 3
  • 14

1 Answers1

5

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

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://example.com:443/$1 [R,L]

To find your apache version you can probably use: apache2 -v

immeëmosol
  • 105
  • 4
TheCompWiz
  • 7,409
  • 17
  • 23
  • Are you sure? The documentation says otherwise, it even suggests using it over Rewrite: http://httpd.apache.org/docs/2.3/rewrite/remapping.html#canonicalhost – NotGaeL Dec 14 '11 at 18:29
  • 3
    is from apache2.3. I suspect you are using 2.2. http://httpd.apache.org/docs/2.2/rewrite/remapping.html#canonicalhost – Mark Wagner Dec 14 '11 at 18:34
  • BTW, a small detail: The RewriteCond should be off (without =) not != on otherwise you get RewriteCond bad delimiters error. Tried to edit but something happens with serverfault it doesn't let me. Please do it yourself if you don't mind so the solution stays corrected for others. Thanks again :) – NotGaeL Dec 14 '11 at 19:12
  • 1
    Done. Although I believe != is completely valid. I'll have to double-check. – TheCompWiz Dec 14 '11 at 19:15
  • it is, I was using != on (with a space in the middle). Dumb again! – NotGaeL Dec 14 '11 at 19:20
  • 1
    reverted back. :D – TheCompWiz Dec 14 '11 at 19:21