Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

How to force HTTPS when a user types in HTTP

Hello Experts,

I have yet another in my series of stupid questions:

A user types in "HTTP://www.somedomain.com" and when it fires I want the user to be redirected to HTTPS of the same domain. So no matter how many times a user tries to access port 80 (HTTP), they can't and are redirected to port 443 or whatever the SSL HTTPS is.

I found this code below but it doesn't work...
Save this as: ForceSSL.inc
 
<%
   If Request.ServerVariables("SERVER_PORT")=80 Then
      Dim strSecureURL
      strSecureURL = "https://"
      strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
      strSecureURL = strSecureURL & Request.ServerVariables("URL")
      Response.Redirect strSecureURL
   End If
%>
	
AND CALL THIS ON YOUR PAGE:
 
<%@Language="VBSCRIPT"%>
<!--#include virtual="/ForceSSL.inc"-->

Open in new window

0
pborregg
Asked:
pborregg
  • 2
1 Solution
 
ALaRivaCommented:
That code you have should work.  Are you sure the include path is correct?

Maybe remove the If Statement, just do a response.redirect to a random page (google.com) and see if the page redirects.  That way if it does, you know that the include worked.

- Anthony
0
 
pborreggAuthor Commented:
Anthony,

I tried that and got this....

http://www.somedomain.com/webproject/0/ <-- it added a '0'??????????

Peter
0
 
pborreggAuthor Commented:
To anyone...

This doesn't work and simply hangs up the browser....

(CODE IS ASP JAVASCRIPT)
if(Request.ServerVariables("SERVER_PORT")==80)
{
      Response.Redirect("https://www.somedomain.com/somedirectory/index.asp");
}
0
 
Wayne BarronCommented:
the only other solution would be to do something that an friend use to do at his ISP.
In the head of the page(s) you can either do a Meta Refresh (or) SQL Redirect

Meta Tag
<meta http-equiv="refresh" content="0;url=https://www.somedomain.com">
(or) (This was the one that was used by my friend)
<%
Response.Redirect("https://www.somedomain.com")
%>

These of course do not check what port you are using.

Good Luck
Carrzkiss
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now