如果指令不工作在Apache的虚拟主机configuration,说“无效的命令”

为什么??

<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! 

“如果”不是Apache能够理解的(在版本2.3之前)。 你可能应该看看mod_rewrite

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

要find你的apache版本,你可以使用: apache2 -v