Apache-2.2
如果指令在 apache VirtualHost conf 中不起作用,則顯示“無效命令”
為什麼??
<VirtualHost *:80> ServerAdmin admin@mydomain.com 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!
“如果”不是 Apache 理解的(在 2.3 版之前)。你可能應該看看 mod_rewrite
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/(.*) https://example.com:443/$1 [R,L]
要找到您的 apache 版本,您可能可以使用:
apache2 -v