This is great! The only modification I would make is to add the query string in one of two ways:
- <%
-
If Request.ServerVariables("SERVER_PORT")=80 Then
-
Dim strSecureURL
-
strSecureURL = "https://"
-
strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
-
strSecureURL = strSecureURL & Request.ServerVariables("URL")
-
strSecureURL = strSecureURL & "?" & Request.ServerVariables("QUERY_STRING")
-
Response.Redirect strSecureURL
-
End If
-
%>
or
- <%
-
If Request.ServerVariables("SERVER_PORT")=80 Then
-
Dim strSecureURL
-
strSecureURL = "https://"
-
strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
-
strSecureURL = strSecureURL & Request.ServerVariables("HTTP_X_REWRITE_URL")
-
Response.Redirect strSecureURL
-
End If
-
%>
and as suggested include this file on a page to force it to use SSL.
BTW, when I wrote a similar script I used HTTPS server variable which returns on or off. Same final result as checking the port for 80 vs. 443.
To see all of the server variables use the following:
- for each x in Request.ServerVariables
-
response.write("<b>" & x & ":</b><br /><pre>" & Request.ServerVariables(x) & "</pre><br /><br />")
-
next
Happy coding:
Matary