Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to force HTTPS when a user types in HTTP

Posted on 2009-05-05
4
Medium Priority
?
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 31

Accepted Solution

by:
Wayne Barron earned 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

661 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