如果指令在 apache VirtualHost conf 中不起作用,则显示“无效命令”

如果指令在 apache VirtualHost conf 中不起作用,则显示“无效命令”

为什么??

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

保存,然后重新启动:

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!

答案1

Apache 无法理解“如果”的含义(在 2.3 版之前)。你可能需要看看 mod_rewrite

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

要查找你的 Apache 版本,你可以使用:apache2 -v

相关内容