Forum Moderators: open

Message Too Old, No Replies

301 redirect. my script isn't working

         

midoriweb

11:15 pm on Feb 15, 2007 (gmt 0)

10+ Year Member



I want to redirect users from my dynamic URL to my static URL. The code I'm trying to use is the following:

<%
If Request.ServerVariables("url") = "/ProductDetails.asp" Then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", """/"" & replace(replace(replace(RS_Product.Fields(""ProductNameShort""), "" "", ""_""), ""."", ""_""), ""!"", """") & ""_p/"" & RS_Product.Fields(""ProductCode"") & "".htm"""
End If
%>

But that code is pulling up this URL:

/%22/%22%20&%20replace(replace(replace(RS_Product.Fields(%22ProductNameShort%22),%20%22%20%22,%20%22_%22),%20%22.%22,%20%22_%22),%20%22!%22,%20%22%22)%20&%20%22_p/%22%20&%20RS_Product.Fields(%22ProductCode%22)%20&%20%22.htm%22)

Is it possible to do what I'm attempting? If it is... what do I need to change in my current code to get this working?

midoriweb

11:25 pm on Feb 15, 2007 (gmt 0)

10+ Year Member



I should probably note... my dynamic URL would be something like:

/ProductDetails.asp?ProductCode=pcode1

My static URL of that same page would be:

/*ProductNameShort*_p/pcode1.htm

My site takes the short product name, replaces spaces with underscores (along with other characters with blanks or underscores), and outputs like the URL shown above.

I'm placing my redirect on my ProductDetails.asp. So when the page is called, it should be able to pull details from my database like ProductNameShort and pcode.

For example... on my site... I'm using the following code to link to my static URL:

<a href="<%=SEOImage("/" & replace(replace(replace(RS_Product.Fields("ProductNameShort"), " ", "_"), ".", "_"), "!", "") & "_p/" & RS_Product.Fields("ProductCode") & ".htm")%>">

That code works and shows a link to the correct static product page. But... I can't seem to modify the above code to get that working inside my 301 redirect.

Any help would be appreciated.

midoriweb

1:14 am on Feb 16, 2007 (gmt 0)

10+ Year Member



I thought about doing something like this (it doesn't work... but it might be easier then what I was doing):

<%
Dim redirectURL
redirectURL = SEOImage("/" & replace(replace(replace(RS_Product.Fields("ProductNameShort"), " ", "_"), ".", "_"), "!", "") & "_p/" & RS_Product.Fields("ProductCode") & ".htm")
If Request.ServerVariables("url") = "/ProductDetails.asp" Then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "redirectURL"
End If
%>

I just need to find a way to make my redirectURL text located in Response.AddHeader actually call the variable I created. Not sure how to do that though :)

midoriweb

7:26 am on Feb 16, 2007 (gmt 0)

10+ Year Member



Got it... I had to remove the quotes around my variable :)