In the beginning there was HTTP…

…but we are in 2017 now

and HTTPS is a must standard, and the fact is, I wanted to have this blog running entirely on a secure connection. My initial plan was to leave the root folder for a future personal website with portfolio, about me and etc. sections and a link to blog in separate folder where I’ll install WordPress.

Installing

With my plan in one hand and FileZila in other I’ve installed WordPress in a couple of minutes. For SSL encryption I need a valid certificate, Altervista hosting can give you a free HTTPS certificate, although it’s not generated by them but by their partner CloudFlare and to get it you must also enable the whole CDN (Content Distribution Network) stuff supplied by CloudFlare. So this was also done.

Redirect

Now we must enable automatic redirect from root to blog folder and .htaccess with mod_rewrite seemed like a reasonable way to go. After a bit of googling and trial and error this is what I came:

BTW follow this link for an excellent mod_rewrite cheat sheet by Dave Child.

Get rid of HTTP

Next step was to redirect each HTTP request to it’s HTTPS counterpart.
Googling the simplest solution is to set the WordPress Address (URL) and Site Address (URL) from http to https. Doing this made the site go in redirection loop.
An alternative was to use .htaccess with another rewrite condition added right after the previous redirect:

Doing this made the site go in redirection loop, again.
Other solutions failed too, and as I found the problem was not my scripts, but the CloudFlare and how they manage https connection.
Remember that I was forced to enable CloudFlare to have a https connection? As it turns out after Altervista made partnership with CloudFlare all connections and request go to CloudFlare over https/http connection, and then CloudFlare contacts Altervista on regular http. And only CloudFlare is allowed to contact Altervista servers over http.

Conclusion

Sometimes it’s really a pain to bump against free hosting limitations… Next time I’ll see hot to fix it!

Leave a Reply