Hack Forums
How to make redirect from http to https - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Webmasters (https://hackforums.net/forumdisplay.php?fid=141)
+---- Forum: Website Construction (https://hackforums.net/forumdisplay.php?fid=50)
+---- Thread: How to make redirect from http to https (/showthread.php?tid=4720774)



How to make redirect from http to https - king1245 - Mar 8, 2015

How to redirect from http to https.


1. redirect http://example.com to https://www.example.com
2. redirect http://www.example.com to https://www.example.com
3. redirect https://example.com to https://www.example.com

Like facebook, google ??

Please help me with code in .htaccess or another


* - Bdwi - Mar 8, 2015

you would need to use the .htdocs and code it up there for it..pm me your skype and ill be able to help u with it.


* - SlightlyNuclear - Mar 8, 2015

You're running a web hosting business and you don't know how to do basic rewrites? Eek.

Are you using Apache, Nginx, or something else?


* - itsMeCherry - Mar 8, 2015

There are many ways to achieve this. If you are using PHP you can do it with a code like this:
PHP Code

<?php 
//
// FORCE SSL 
//
    // Use HTTP Strict Transport Security to force client to use secure connections only
    
$use_sts = false;

    
// iis sets HTTPS to 'off' for non-SSL requests
    
if ($use_sts && isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
        
header('Strict-Transport-Security: max-age=31536000');
    } elseif (
$use_sts) {
        
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], true, 301);
        
// we are in cleartext at the moment, prevent further execution and output
        
die();
    }
//
// FORCE SSL END
// 



* - dkoder - Mar 8, 2015

IF SSL is installed on your server.

Forcefully Redirect http to https via .htaccess file

""""""
RewriteEngine On
RewriteCond %{HTTP_HOST} ^websitedomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://websitedomain.com/$1 [R,L]
""""""