我正在一个 Drupal 站点上工作,客户要求我们删除“www”。从网址。这非常简单,我以前做过;我只是在 Drupal 生成的 .htaccess 文件中注释掉建议的行,如下所示:
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
熟悉 Drupal 的 .htaccess 的人会知道环境变量protossl
设置在文件的顶部,如下所示:
# Set "protossl" to "s" if we were accessed via https://. This is used later
# if you enable "www." stripping or enforcement, in order to ensure that
# you don't bounce between http and https.
RewriteRule ^ - [E=protossl]
RewriteCond %{HTTPS} on
RewriteRule ^ - [E=protossl:s]
这在我的本地环境中运行良好,但是当我将更改部署到生产站点时它会中断。按预期www.mysite.com
重定向到,但也重定向到而不是. 即使变量应该“打开” ,该变量似乎也返回“关闭”。mysite.com
https://www.mysite.com
mysite.com
https://mysite.com
%{HTTPS}
我可以直接去https://mysite.com
,它工作得很好。该站点的 Apache 访问日志在我期望的位置显示“https://”,我的所有 HTTP 请求也是如此。该站点正在使用负载平衡器(平衡器中只有一个节点)的 RackSpace 服务器上运行。SSL 证书位于 RackSpace 负载平衡器上。我尝试了以下步骤,但没有任何结果:
- 将 RewriteCond 替换为
RewriteCond %{ENV:HTTPS} on [NC]
- 将 RewriteCond 替换为
RewriteCond %{SERVER_PORT} ^443$
- 上述 RewriteCond 的多种变体和组合
- 添加
$conf['https'] = TRUE;
到 settings.php
这让我的同事和我发疯了。任何人都可以帮忙吗?