Magento index.php 301将http重定向到https

时间:2016-09-26 09:37:00

标签: php http magento redirect https

我有问题,我的项目在nginx上运行,所以我不能通过htaccess进行重定向。解决方案是我需要使用php将index.php重定向到https。

实施例

http://example.com/shoeshttps://example.com/shoes

此外,Google上的大多数示例建议使用htaccess,这就是为什么我在这里。

1 个答案:

答案 0 :(得分:2)

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();
}

找到适合我的解决方案。

P.S。 WWW str替换是这里不需要的附加功能