Jump to content

Using Servervariables Request For A 301 Redirect


mboehler3

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"

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...