Jump to content
Sign in to follow this  
mboehler3

Using Servervariables Request For A 301 Redirect

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)?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...