gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 17:06:28 25 4
gpt4 key购买 nike

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

例子

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

此外,谷歌上的大多数示例都建议使用 htaccess,这就是我来这里的原因。

最佳答案

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

找到了适合我的解决方案。

附注WWW str replace 是这里不需要的附加功能

关于php - Magento index.php 301 将 http 重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39699343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com