Jump to content

Redirecting to https


forumnz

Recommended Posts

When someone goes to my website I 'example.com' instead of being http, I want it to go to https. How do I do this? Using FTP I had 2 folders..

One was httpdocs and the other was httpsdocs, so I put an index file in the httpdocs folder that redirects to https://www.mysite.com/ but it say that the page is never going to complete.

What should I do instead?

Link to comment
https://forums.phpfreaks.com/topic/108196-redirecting-to-https/
Share on other sites

https:// is a secure connection link to the server used for credit card transactions or input of secure information like social security numbers.

 

You do not want to use this as an everyday connection to your web server. It uses encryption, so your server will get a hit from performance. Therefore, logically you wouldn't want to do what you are trying to do.

Link to comment
https://forums.phpfreaks.com/topic/108196-redirecting-to-https/#findComment-554603
Share on other sites

When it "never completes" you probably have set your redirect in a loop -somehow. You don't need two folders with the same content (where you think one is http and the other one is https)... or has your web-provider set it up that https only works for your https folder (or did you create this folder)?

 

Anyway: Imagine your http://domain goes to "htdocs" and your https://domain goes to https and you want everything working with https. Put your homepage in the https folder and in the http folder you simply need one file to redirect to the https folder. in the redirect-file you put "    header ("location: ../pathtohttps/myfile.php");    "

But be sure there is NO redirect in the https-target-file (except to a completely other file)

 

If https://domain and http://domain can point to the same directory you would just need one homepage in this folder and put a redirect-file in front of your homepage, like an index.php file that points to index2.php (or whatever) and in the index.php file you get the port number of the clients connection (with $_SERVER['SERVER_PORT'] ) and redirect them to

if($_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 8080){ //non https

        'https://'.$HTTP_HOST.$REQUEST_URI;
        $href = "https://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; 
        header ("location: ".$href);
}

A file with this code at the top redirects itself to itself if the connection is non https!

 

 

Depending on what you want to do with https its a good idea or a bad idea. If you don't want hackers to find out WHAT your users do on your site you can encrypt the whole homepage. otherwise i have to agree with TheFilmGod ... https also slows down the speed of your site but if you are the only person on a high-tech server with crypto co-processors it won't hurt you ;)  ;D

 

kind regards

Link to comment
https://forums.phpfreaks.com/topic/108196-redirecting-to-https/#findComment-554683
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.