In your program code, you evaluate the protocol and redirect using 301 (server-side). This is not done in the browser .
You can do this in ASP.NET in the Global.asax file
I am not sure about other programming languages ββ(PHP, Ruby, etc.). Others are free to call and edit their answer with more examples if they wish.
if(!Request.IsSecureConnection) { string redirectUrl = Request.Url.ToString().Replace("http:", "https:"); HttpContext.Current.Response.Status = "301 Moved Permanently"; HttpContext.Current.Response.AddHeader("Location", redirectUrl); }
I think you can do this by default in Apache using .htaccess, but as far as I can tell, if you want to do this in IIS you need to run asp script or include it in your .net application, I could be wrong, but this is what I encountered in my trials.
source share