【问题标题】:Redirect from HTTPS to HTTP in OpenShift w/ custom domain在带有自定义域的 OpenShift 中从 HTTPS 重定向到 HTTP
【发布时间】:2014-09-18 10:19:16
【问题描述】:

我有一个自定义域的青铜级帐户。我有一个 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

如您所见,我将一个域(安全)配置为使用 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>

【问题讨论】:

  • 如您所见,我的 htaccess 规则已经按照该问题的答案进行设置。我认为带有 openshift 的配置有一些特定的东西。你会注意到我的安全子域 /already/ 尽管完全没有 htaccess 规则,但它仍然可以正常工作。

标签: apache .htaccess mod-rewrite ssl openshift


【解决方案1】:

您已经接近了,但 SERVER_PORT 是使用 OpenShift 的错误方式 (see here)。

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,它解决了我的问题。
猜你喜欢
  • 2014-11-27
  • 2014-05-28
  • 1970-01-01
  • 2015-12-24
  • 2019-02-12
  • 2016-01-30
  • 1970-01-01
  • 2018-12-04
  • 2021-07-30
相关资源
最近更新 更多