How to fix cloudflare ssl issue

Sometimes cloudflare SSL cause some errors. Such as it start adding a trailing :80 to the url. In this condition, at this line in your index.php file to fix that issue. If you still have any error then please contact me.

// Fix SSL for cloudflare
if (isset($_SERVER['HTTP_CF_VISITOR'])) {
    if (preg_match('/https/i', $_SERVER['HTTP_CF_VISITOR'])) {
        $_SERVER['HTTPS'] = 'On';
        $_SERVER['HTTP_X_FORWARDED_PORT'] = 443;
        $_SERVER['SERVER_PORT'] = 443;

I use cloudflare as CDN with the “Free SSL” option and the “Always SSL” rule. So my browser send the request on port 443, the request is delegated to the (Apache) webserver. But on the Apache site, the request comes from the standard 80 port (I use only the flexible SSL option).