TL;DR: I want to redirect https
to http
on all pages except for admin/login, where I want the exact opposite to happen. I also want www
redirected to bare domain name. (UPDATE: Check Update 3 for the answer)
As is probably clear from the title, I have a WordPress blog hosted on OpenShift for free. I have a custom domain bought from GoDaddy. I’m using cloudflare so I can have free SSL.
Here’s my configuration:
CloudFlare DNS:
CloudFlare Page Rules:
This is what worked best. I actually wanted to have this rule:
*ghostlessmachine.com/* -> https://ghostlessmachine.com/$1
But I ran into even more problems like that, even though it seems to be pretty much what I’m supposed to do according to this CloudFlare article. Actually, initially I wanted to only force SSL in admin pages, but I didn’t even know how to attempt that. I thought of using two page rules, like this:
*ghostlessmachine.com/* -> http://ghostlessmachine.com/$2
*ghostlessmachine.com/wp-* -> http://ghostlessmachine.com/$2
But I had no luck.
Here’s my OpenShift configuration:
When I write ghostlessmachine.com
in my address bar, it correctly takes me to https:...
. I have shared a link, however (https://ghost...
), and one person has reported not being able to access it. I couldn’t reproduce locally.
When I try www.ghost...
, I get:
This webpage has a redirect loop
ERR_TOO_MANY_REDIRECTS
Does anybody have any idea what I’m doing wrong? I’ve lost track of how many different configurations I’ve tried, but nothing seems to work.
Thanks!
UPDATE
OK, so following the advice in the comment I managed to get the situation a bit better. Still it’s counter intuitive for me how the article I initially linked to just didn’t get the job done while the other SO question did. So here’s what I’ve changed:
- Deleted the
www.ghost...
alias from OpenShift. - Changed CloudFlare’s CNAME record from
www -> blabla.rhcloud.com
towww -> ghostlessmachine.com
- Created this Page Rule:
www.ghostlessmachine.com/* -> http://ghostlessmachine.com/$1
Now both ghost...
and www.ghost...
work and take me to http://ghost...
. However, if I type https://ghost...
, it also works without redirecting me to simple http. This is a problem.
I tried using this Page Rule instead:
ghostlessmachine.com/ -> http://ghostlessmachine.com/$2
So that I got https://
, http://www
, www
, everything redirected to http://ghost...
, but it doesn’t work. I can’t access my blog anymore and whatever address I try I get ERR_TOO_MANY_REDIRECTS.
UPDATE 2
Here’s my full setup after all suggestions:
htaccess:
wp-config.php:
CloufFlare:
Result:
https -> http
on non-admin/login pages: WORKING â- Trying to access admin/login pages: ERR_TOO_MANY_REDIRECTS
Update 3
This did the trick:
I still don’t understand why this works and the rest doesn’t though. This was basically a series of rather blind trial and error with some input from Allen here and Simon in the CloudFlare support page. In any case, all my requirements are respected now, thanks!
make sure following in your wp-config.php file:
look over here: Force non-WWW but force https across all of wordpress & the entire domain
for redirect everything else to non-https, you can add following into your root .htaccess file, before the wordpress rewrite:
Update:
CloudFlare’s Page rule has following “Page rule priority is determined by their position in the list. If multiple rules match a URL, rules at the top take higher priority. “
let’s see what happens before:
rule, match found, then it goes to
http://www.ghostlessmachine.com/wp-admin!
no rewrite, goes down to 3rd rule, oops, it needs goto
https://www.ghostlessmachine.com/wp-admin!
this is how the loop comes