Results 1 to 2 of 2

Thread: Force https

  1. #1
    charlesh's Avatar
    charlesh is offline Master Glow Jedi
    Join Date
    Aug 2006
    Location
    Atlanta, GA - better than you imagined it would be.
    Posts
    189

    Default Force https

    If you're running ssl and don't want a user to get to a page unsecured, i've created this function to force https based on URI. If you put it in an include file and then run the function at the top of your script, it will redirect back to the page with https invoked.

    For those pages that don't require https, to minimize server load, i've created the oppposite function. Let me know how it works out if you use it:

    PHP Code:
    function forcehttps(){
      if (!isset(
    $_SERVER['HTTPS']))
     
      {
       
    $ref $_SERVER['REQUEST_URI'];
       
    header("Location:https://wwww.yoursite.com".$ref);
       exit;
     
      }
    }
    function 
    killhttps(){
      if (isset(
    $_SERVER['HTTPS']))
     
      {
       
    $ref $_SERVER['REQUEST_URI'];
       
    header("Location:http://wwww.yoursite.com".$ref);
       exit;
     
      }


  2. #2
    sergey is offline Master Glow Jedi
    Join Date
    Aug 2005
    Posts
    472

    Default

    Thanks for sharing it with us Charles. You can also redirect non-secure urls to secure links by adding one of the following directives to .htaccess file:

    Code:
     RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    or

    Code:
     RewriteEngine On
    RewriteCond %{SERVER_PORT} !443
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Similar Threads

  1. [How To] Redirect from HTTP to HTTPS using mod_rewrite
    By sergey in forum Knowledge Base
    Replies: 1
    Last Post: 05-13-2008, 01:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16