简体   繁体   中英

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.

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.

ps WWW str replace was additional functionality that isn't needed here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM