469,917 Members | 1,473 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

HTTP to HTTPS redirect resulting in a loop

Just before I go an tell my sys admin that the server has problems I wanted to run this by everyone on here. Basically we have a few pages that need to be sent over https. Everything I have found on the internet resulted in this code

Expand|Select|Wrap|Line Numbers
  1. If (Request.ServerVariables("HTTPS") = "off") Then
  2.         srvname = Request.ServerVariables("SERVER_NAME")
  3.         scrname = Request.ServerVariables("SCRIPT_NAME")
  4.         Response.Redirect("https://" & srvname & scrname)
  5.     End If
I will say that this code has worked for me over a month and then all of the sudden it stops working and always gives a redirect loop error. I have already checked that the ServerVariables is "off" during an http request and it is "on" during an https request.

Honestly, this code should work and it has been working until recently. Unfortunately my sysadmin believes it is faulty code and told me to rewrite it, claiming that his server could "have no faults."

Anyone have an idea or should this code work? btw it is being run on IIS 6
Jan 19 '09 #1
1 3822
164 Expert 100+
Just a thought, but are you sure you are correctly comparing strings? I use this, which returns a numeric value so I don't have to worry about uppercase and lowercase comparison differences:

Expand|Select|Wrap|Line Numbers
  1. i = Request.ServerVariables("SERVER_PORT_SECURE")
  2. '// returns 1 or 0
You could still use yours, but ensure the case of the result is what you expect:

Expand|Select|Wrap|Line Numbers
  1. If (lcase(Request.ServerVariables("HTTPS")) = "off") Then 
  2.    srvname = Request.ServerVariables("SERVER_NAME") 
  3.    scrname = Request.ServerVariables("SCRIPT_NAME") 
  4.    Response.Redirect("https://" & srvname & scrname)
  5. End If 
Jan 20 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Bob Hansen | last post: by
1 post views Thread by dave | last post: by
3 posts views Thread by Raymond Tam | last post: by
14 posts views Thread by david | last post: by
7 posts views Thread by =?Utf-8?B?YzY3NjIyOA==?= | last post: by
8 posts views Thread by howa | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.