Casey
Casey

Reputation: 6326

Redirect from HTTPS to HTTP in OpenShift w/ custom domain

I've a Bronze account with a custom domain. I've a secure subdomain configured to use an SSL cert, which is working fine. However, I want to force HTTP (ie.e., no SSL) on the root domain. However when I browse to https://example.com I am getting the shared SSL certificate that belongs to example-myuser.rhcloud.com.

How can I disable HTTPS for for all subdomains except secure?

My aliases are set up as:

Alias                 Has Certificate? Certificate Added
--------------------- ---------------- -----------------
example.com        no               -
secure.example.com yes              2014-07-26
www.example.com    no

As you can see I have one domain (secure) configured to use an SSL cert.

My attempt at this was with the following htaccess rules, but they don't work.

<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>

Upvotes: 3

Views: 1770

Answers (1)

luciddreamz
luciddreamz

Reputation: 2093

You're close, but SERVER_PORT is the wrong way to go on 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]

Upvotes: 2

Related Questions