我的 .htaccess 文件位于根目录中,并为多个网站提供服务。
它包含一个 RewriteEngine 块。
如果主机不是(www)www.example.com,我想阻止 Apache 评估规则:
RewriteEngine On
RewriteBase /
#If this is not about example.com, it is probably about our other websites, exit here
RewriteRule %{HTTP_HOST} !^(www|)example.com$ - [L]
但是,这会导致 500 内部错误。可能由于使用 {HTTP-HOST} 是 RewriteRule 指令。
所以我现在正在考虑这样的事情:
RewriteCond %{HTTP_HOST} !^(www|)example.com
RewriteRule (.*) $1 [L]
但这需要 Apache 重写并且不利于性能。
有人建议吗?