472,373 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

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 3977
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

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

Similar topics

by: Bob Hansen | last post by:
I am using the following code in my default.asp page to redirect the page from HTTP to HTTPS <% if Request.ServerVariables("HTTPS") = "off" Then Response.Redirect("https://" &...
by: dave | last post by:
Hello I have one simple form (myform.asp) and it posts to query.asp I had put below code in both file on top of the page to redirect this two pages in https:// so any one can access it thru http...
by: McKirahan | last post by:
I have an ASP site, an SSL certificate, and an {Order page}. I want to use "https" for the {Order page} and "http" for all others. Each page "includes" a common ".asp" file which detects the...
by: Raymond Tam | last post by:
When I am using server-side button to switch from https to http by using response.redirect "http://a.apsx" in response to the client event, I am still at the https environment (ie. the address bar...
by: Dabbler | last post by:
I'm sending users to a secure page https to fill out a registration form. When they're done I show a thank you page. I need to return the user to http mode after filling out the form. If I use...
by: david | last post by:
I have developed web forms including login by using ASP.NET via HTTP. Now I want to secure the connection from client to the server via HTTPS. How can I configure the server or something else to...
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am trying to set this up using asp code and IIS configuration. But it seems not working. Here it is the way I am doing. In IIS I set up a virtual directory with secure communication, I...
by: howa | last post by:
a page currently in HTTPS, I force the client to redirect to another page using HTTP under the same domain (e.g. abc.com), i.e. header("Location: http://www.abc.com/index.php"); IE...
by: Raven | last post by:
Hi, I have a problem with a server side redirect from a secure page to a non-secure page (same domain name, same folder) I have added some test code that can display the target URL and that...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.