HTTP to SSL redirect – just with PHP

Few month ago i wrote how to integrate Cloudflare SSL to your WordPress website.
We used some little tricks in wp-config and Apache Configuration and Cloudflare SSL began working like pure SSL.

Now i am sharing another little trick which doesn’t require apache or nginx settings change.

<?php
/**
* The base configuration for WordPress
* ...
* @package WordPress
*/
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';
if ( $_SERVER['HTTPS']!='on') {
header('location: https://YOUR_DOMAIN_HERE'.
$_SERVER["REQUEST_URI"]);
exit;
}
define('FORCE_SSL_ADMIN', true);
//..... rest wp-config lines here


Discover more from WP DEV - Elvin Haci

Subscribe to get the latest posts sent to your email.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from WP DEV - Elvin Haci

Subscribe now to keep reading and get access to the full archive.

Continue reading