Forum Moderators: open

Message Too Old, No Replies

301 URL redirection

         

Landyman

6:47 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



Hi, I'm kinda new to the Windows servers, so please excuse me if I seem to not know what I'm talking about.
This is what I have:
[somesite.com...]

and I want to redirect to:
[somesite.com...]

Also, since the default.asp page without a query string is an acutal page, I need it so it doesn't redirect. I need to only redirect the pages with query strings.
Any help would be great!
Thanks!

dotme

7:42 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



foo = cstr(request("foo"))
If len(foo) > 0 Then
url = "/some directory/" & foo & "/default.asp
response.redirect url
End If

The above *should* work when placed in ASP code before the HEAD in the HTML, although if you truly want a 301, you will have to also add 301 headers within the If-Then statements too. Not sure how that's done, but I'm sure someone here can help!

JD

Landyman

7:59 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



Thanks dotme.
OK, based on my knowledge of 301 and your code, this is what I have so far to put into the top of the file.

<%
foo = cstr(request("foo"))
If len(foo) > 0 Then
url = "/some directory/" & foo & "/default.asp

Response.Status = “301 Moved Permanently”
Response.addheader "Location", "http://www.somedomain.com" & url
Response.End

End If
%>

Unfortuately, this code is for a client. I do not have an IIS ASP server to use to check the code. Does this appear right to anybody else for what I'm trying to do?

Landyman

7:32 pm on Apr 30, 2004 (gmt 0)

10+ Year Member



OK.. I figured it out. If anybody wants to know, I'm posting this as a resolve to this forum.
<%
q_string = Request.QueryString("parameter_name")
if len(q_string)>0 then
url = "/some_directory/" & q_string & "/default.asp"
domain = Request.ServerVariables("HTTP_HOST")
Response.Status = "301 Moved Permanently"
Response.addheader "Location", "http://" & domain & url
Response.End
end if
%>

Thanks