301 Redirect for URLs with Variables
-
28-10-2019 - |
Question
I am doing 301 redirects for old URLs in a situation where I can't use Web.Config at all, so there's no rewrite module capability. So I have been using this simple code on individual files:
<%@Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader ( "Location","newurl.html" )
%>
My problem is that there is one page (index.asp) where variables are passed in through the URL like this:
domain.com/index.asp?PageAction=VIEWPROD&ProdID=71 domain.com/index.asp?PageAction=VIEWPROD&ProdID=72
I want to set up conditional 301 redirects so that when the URL is ProdID=71 it 301s to one specific page, and when the URL is ProdID=72, it 301s to a different page.
So far I have this simple code:
<%
DIM strPageAction
strPageAction = Request.QueryString("PageAction")
DIM strProdID
strProdID = Request.QueryString("ProdID")
%>
<%
IF strPageAction = "VIEWPROD" AND strProdID = "71" THEN
ELSE
END IF
%>
<%
IF strPageAction = "VIEWPROD" AND strProdID = "72" THEN
ELSE
END IF
%>
Does anyone know how I could get a 301 redirect in there for the "THEN" condition? I am very new to this, so perhaps I am missing an easy solution...
"Response.Redirect" works but gives a 302 instead of a 301. The new option of "Response.RedirectPermanent" doesn't work on my hosting.
Solution
Well, I found some code that did the job:
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
if Request.QueryString("PageAction") = "VIEWPROD" and Request.QueryString("ProdID") = "71" then
Response.AddHeader "Location", "http://www.foxnews.com"
else if Request.QueryString("PageAction") = "VIEWPROD" and Request.QueryString("ProdID") = "72" then
Response.AddHeader "Location", "http://www.apple.com"
end if
end if
%>