Solved

How to force HTTPS when a user types in HTTP

Posted on 2009-05-05
4
280 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 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP get fieds value 2 22
Jquery 7 33
How to add custom html-5 element to a dynamically generated link? 4 24
How do I add counter to html listbox using jquery 2 26
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

733 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