Solved

How to force HTTPS when a user types in HTTP

Posted on 2009-05-05
4
277 Views
Last Modified: 2012-06-21
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
Comment
Question by:pborregg
  • 2
4 Comments
 
LVL 10

Expert Comment

by:ALaRiva
ID: 24310324
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
 

Author Comment

by:pborregg
ID: 24310445
Anthony,

I tried that and got this....

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

Peter
0
 

Author Comment

by:pborregg
ID: 24310950
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
 
LVL 30

Accepted Solution

by:
Wayne Barron earned 500 total points
ID: 24317817
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question