Jump to content

Using Servervariables Request For A 301 Redirect


mboehler3
 Share

Recommended Posts

I am trying to 301 redirect a page, and I want to grab the Server Name using Request.ServerVariables. My 301 code looks like this:

<%@ Language=VBScript %><%Response.Status="301 Moved Permanently"Response.AddHeader "Location", "https://<%= Request.ServerVariables("SERVER_NAME") %>/website.asp"%>

But when I try to access the old page to see the redirect, I get this error in my browser:

Microsoft VBScript compilation error '800a0401'Expected end of statement/surechoice/accounting-practice-management-insights.asp, line 4Response.AddHeader "Location", "https://<%= Request.ServerVariables("""SERVER_NAME""")-----------------------------------------------------------------------^

Is there a way to do this so that it will work (ie. read the quotations)?

Link to comment
Share on other sites

That's because you're nesting ASP blocks. You can't have a block inside another block You basically have this:

<% <%= Request.ServerVariables("SERVER_NAME") %> %>

I don't know ASP, but you need to use a concatenator to append a variable to a string. I think in ASP the concatenator is &, but I'm not sure.

Response.AddHeader "Location", "https://" & Request.ServerVariables("SERVER_NAME") & "/website.asp"

  • Like 1
Link to comment
Share on other sites

That's because you're nesting ASP blocks. You can't have a block inside another block You basically have this:
<% <%= Request.ServerVariables("SERVER_NAME") %> %>

I don't know ASP, but you need to use a concatenator to append a variable to a string. I think in ASP the concatenator is &, but I'm not sure.

Response.AddHeader "Location", "https://" & Request.ServerVariables("SERVER_NAME") & "/website.asp"

This works, thank you.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...