Add Forfully Redirect http to https using php code without .htaccess

Add Forfully Redirect http to https using php code without .htaccess

Add Forfully Redirect http to https using php code without .htaccess

This tutorial is for redirecting the http URL to https using the PHP code if your .htaccess will not work for the SSL. It will just redirect all your HTTP URLs to HTTPS without using the .htaccess if your server HTTPS is not on. Just follow the step, and you can get your own redirection.

Step 1)

Just put this code in your main root file or connection file, which is included everywhere inyour project. So every time a URL is scanned with this code, if it finds the http, it will convert it into https.

if (!(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || 
   $_SERVER['HTTPS'] == 1) ||  
   isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&   
   $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'))
{
   $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
   header('HTTP/1.1 301 Moved Permanently');
   header('Location: ' . $redirect);
   exit();
}

26 responses

26 thoughts on “Add Forfully Redirect http to https using php code without .htaccess

  1. tetracycline 500 mg dosage

    Hello! I just wanted to ask if you ever have any trouble with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no back up. Do you have any methods to protect against hackers?

  2. avanafil

    I’ll immediately clutch your rss as I can’t in finding your email subscription link or newsletter service. Do you have any? Kindly allow me know in order that I may subscribe. Thanks.

  3. loperamide 2mg capsules

    I will immediately snatch your rss feed as I can not in finding your email subscription hyperlink or newsletter service. Do you have any? Please permit me recognise in order that I may just subscribe. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *