Solved

How to force HTTPS when a user types in HTTP

Posted on 2009-05-05
4
274 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
Comment Utility
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
Comment Utility
Anthony,

I tried that and got this....

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

Peter
0
 

Author Comment

by:pborregg
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now