dozc1071 2016-09-26 01:36 采纳率: 100%
浏览 131
已采纳

Magento index.php 301将http重定向到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.

  • 写回答

1条回答 默认 最新

  • doufan2541 2016-09-27 01:46
    关注
    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥35 西门子博图v16安装密钥提示CryptAcquireContext MS_DEF_PROV Error of containger opening
  • ¥15 mes系统扫码追溯功能
  • ¥40 selenium访问信用中国
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?