Macas
Macas

Reputation: 580

Magento index.php 301 redirect http to https

I have a problem, my project is running on nginx, so I cant do redirects via htaccess. Solution is that I need to use index.php using php to redirect http to https.

Example

http://example.com/shoes to https://example.com/shoes

Also, most of the examples on google suggest using htaccess, thats why I'm here.

Upvotes: 1

Views: 345

Answers (1)

Macas
Macas

Reputation: 580

if(!$_SERVER['HTTPS'] || strtolower($_SERVER['HTTPS']) != 'on' ){
    header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://' . str_replace('www.','',$_SERVER['HTTP_HOST']) . $_SERVER['REQUEST_URI']);
    exit();
}

Found a solution that worked for me.

p.s. WWW str replace was additional functionality that isn't needed here

Upvotes: 2

Related Questions