The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

redircting http:// to https://

Discussion in 'General Discussion' started by ctbhost, Nov 7, 2004.

  1. ctbhost

    ctbhost Well-Known Member

    Joined:
    May 31, 2002
    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    i have found a snipit that will redirect the visitor to the https:// page even if they try to access via the http://

    put this in the verry begining of the index.php file

    PHP:
    if ( !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ) { 
       
    header ('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); 
       exit(); 
     
  2. LA_fro

    LA_fro Well-Known Member

    Joined:
    Jun 3, 2004
    Messages:
    50
    Likes Received:
    1
    Trophy Points:
    8
    why not setup a mod_rewrite in the .htaccess file? This is of course assuming you have mod_rewrite setup

    RewriteEngine On
    RewriteCond %{SERVER_PORT} !443
    RewriteRule ^(.*)$ https://www.x.com/$1 [R,L]
     
  3. dezignguy

    dezignguy Well-Known Member

    Joined:
    Sep 26, 2004
    Messages:
    534
    Likes Received:
    0
    Trophy Points:
    16
    It's always preferable to put such configs into the httpd.conf itself, if at all possible. htaccess is convenient, especially if you have no other options (ie, no access to httpd.conf), but if you have a choice, go for httpd.conf.

    LA-fro, I can't tell just from reading it whether your rewrite rule will work both with or without a trailing slash. I'm not sure if the default 'trailing slash fix' applies here.

    My rewrite rule to ensure that a directory is always accessed using ssl is very similar to yours... I just have
    Code:
    (/)?
    in front of your
    Code:
    (.*)
    That ensures that both slashes and no-slashes will work.
     
  4. prasath

    prasath Registered

    Joined:
    Feb 21, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
Loading...

Share This Page