Redirect domain Http to Https://

Discussion in 'Programming' started by imteaz, Sep 14, 2008.

  1. #1
    imteaz, Sep 14, 2008 IP
  2. ryandanielt

    ryandanielt Well-Known Member

    Messages:
    1,797
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    185
    #2
    read more on htaccess files I know some people that have done this through there htaccess file.
     
    ryandanielt, Sep 14, 2008 IP
  3. imteaz

    imteaz Notable Member

    Messages:
    4,411
    Likes Received:
    255
    Best Answers:
    0
    Trophy Points:
    225
    #3
    i have tried 2 or 3 code, none of them worked.
     
    imteaz, Sep 14, 2008 IP
  4. ryandanielt

    ryandanielt Well-Known Member

    Messages:
    1,797
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Well if I get some time soon then I will try to figure it out and then I will let you know. No Promises tho!
     
    ryandanielt, Sep 14, 2008 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    PHP:

    
    function redirectToHTTPS()
    {
      if($_SERVER['HTTPS']!="on")
      {
         $redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
         header("Location:$redirect");
      }
    }
    
    PHP:
    Apache:

    
         RewriteEngine On
         RewriteCond %{SERVER_PORT} !^443$
         RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [L,R]
    
    or
    
      RewriteEngine On
      RewriteCond %{HTTPS} !on
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    
    PHP:
    Peace,
     
    Barti1987, Sep 14, 2008 IP
  6. imteaz

    imteaz Notable Member

    Messages:
    4,411
    Likes Received:
    255
    Best Answers:
    0
    Trophy Points:
    225
    #6
    ahh i made it work, thanks all.
     
    imteaz, Sep 14, 2008 IP