在OpenShift中使用自定义域名将HTTPS重定向到HTTP

3
我有一个带有自定义域名的青铜账户。我配置了一个secure子域名以使用SSL证书,它正常工作。然而,我想在根域名上强制使用HTTP(即没有SSL)。但是,当我浏览https://example.com时,我得到了属于example-myuser.rhcloud.com的共享SSL证书。 如何禁用除secure之外的所有子域名的HTTPS? 我的别名设置如下:
Alias                 Has Certificate? Certificate Added
--------------------- ---------------- -----------------
example.com        no               -
secure.example.com yes              2014-07-26
www.example.com    no

你可以看到,我有一个域名(secure)配置使用SSL证书。
我尝试了以下htaccess规则,但它们没有起作用。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# disable https on the root
RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} ^example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example\.com [NC]
RewriteRule (.*) http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

1
可能是重复的问题:如何编写htaccess将子域名重定向到https - jww
1
正如您所见,我的htaccess规则已经按照该问题的答案建议进行设置。我认为这与openshift的配置有关。请注意,尽管没有htaccess规则,我的安全子域名/已经/按预期工作。 - Casey
1个回答

2

你快了,但在OpenShift上使用SERVER_PORT是错误的方法(请看这里)。

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# disable https on the root
RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteCond %{HTTP_HOST} ^example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example\.com [NC]
RewriteRule (.*) http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

这个技巧对我来说不起作用,原因不明。我所做的就是在DNS上添加了URL重定向记录,将“www”重定向到没有“www”的URL,问题得到了解决。 - Ruslan Platonov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接