How to ridirect http to https with uot .htaccess

Discussion in 'Site & Server Administration' started by Kaiti, Nov 21, 2017.

  1. #1
    there is some way to redirect from http to https withuot .htaccess
     
    Kaiti, Nov 21, 2017 IP
  2. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #2
    .htaccess is surely the best way to do this, but you can also redirect traffic to https using PHP

    if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
        $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: ' . $redirect);
        exit();
    }
    Code (markup):
     
    phpmillion, Nov 22, 2017 IP
  3. Kaiti

    Kaiti Well-Known Member

    Messages:
    136
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    133
    #3
    where I add this? Please
     
    Kaiti, Nov 22, 2017 IP
  4. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #4
    At the top of PHP file(s). Before any other code.
     
    phpmillion, Nov 23, 2017 IP
  5. Kaiti

    Kaiti Well-Known Member

    Messages:
    136
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    133
    #5
    I can add in index.php or in header.php?
     
    Kaiti, Nov 23, 2017 IP
  6. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #6
    At the top of your PHP file(s). It impossible to tell which file exactly you need to add this code to, because only you know the structure of your files.
     
    phpmillion, Nov 24, 2017 IP
  7. Kaiti

    Kaiti Well-Known Member

    Messages:
    136
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    133
    #7
    I'm using Wordpress
     
    Kaiti, Nov 24, 2017 IP
  8. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #8
    Then simply look at WordPress files to check which files are served first, and include code there.
     
    phpmillion, Nov 24, 2017 IP