apache - 在带有自定义域的 OpenShift 中从 HTTPS 重定向到 HTTP

标签 apache .htaccess mod-rewrite ssl openshift

我有一个带有自定义域的青铜级帐户。我有一个配置为使用 SSL 证书的 secure 子域,它工作正常。但是,我想在根域上强制使用 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>

最佳答案

您很接近,但是 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]

关于apache - 在带有自定义域的 OpenShift 中从 HTTPS 重定向到 HTTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24974735/

相关文章:

apache - 使用 Apache 将端点转发到同一主机上的不同端口

css - RewriteRule 和缺乏引用

php - 通配符 SSL 子域转发

c++ - apache 服务器上的 fcgi 与 mod_fastcgi

java - 向大型 xlsx 文件添加一行(内存不足)

eclipse - Stardust和Activiti有什么区别

java - 如何在 https 和端口 80 中运行 tomcat?

php - Codeigniter htaccess 添加了一个额外的正斜杠

php - 使用 htaccess 将 root 重定向到子文件夹而不在 URL 中显示它

apache - 使用 htaccess 将 HTTPS 重定向到 http 重定向