Forum Moderators: open

Message Too Old, No Replies

Redirect whilst retaining query string

         

indigojo

3:41 am on Jun 10, 2004 (gmt 0)

10+ Year Member



I have recently changed site architecture and need to somehow do a redirect whilst keep the query string alive.

URLS' look like this oldpage.asp?id=1

and new page looks like this

newpage.asp?id=1

I'd like to remove the old page and redirect all calls for those old pages to my new page with the same query string.

Can anyone tell me if this can be done easily and how or point me to a good source.

defanjos

5:51 am on Jun 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think this will work:

<%
dim id

if request("id")<>"" then
id=request("id")
response.redirect "newpage.asp?id=" & id
end if
%>

Place at top of oldpage.asp

indigojo

6:09 am on Jun 10, 2004 (gmt 0)

10+ Year Member



i got it working in the end with this

<% response.redirect("newpage.asp" & "?id=" & request.querystring("id")) %>

TheDave

6:15 am on Jun 10, 2004 (gmt 0)

10+ Year Member



Just off the top of my head, you could use something like this (havnt tested it):

'set the initial page
u = "http://blah/blah.asp?"

'loop through each querystring
for each q in request.querystring
u = u & Server.URLEncode(q) & "=" & Server.URLEncode(request.querystring(q))
u = u & "&"
next

'remove the last &
u = left(u, len(u)-1)

response.redirect u

edit - Come to think of it, I'm not sure that the Server.URLEncode is nescessary, but couldnt hurt

sqlgod

7:28 pm on Jun 10, 2004 (gmt 0)

10+ Year Member



or use Request.Querystring to capture the whole querystring

i.e.

response.redirect("someurl?" & Request.Querystring)

mattglet

9:20 pm on Jun 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Request.Servervariables("QUERY_STRING") will also work.

-Matt