I have to look up how to implement a 301 redirect in ASP every few months, so I’m putting this up as a personal reference.
<%@ Language="VBScript" %> <% Response.Status = "301 Moved Permanently" Response.AddHeader "Location", "http://domain.com/page.asp" Response.End %>
It seems that the value of Location can be a relative path and the redirect will still function.
I know this should be so easy….. but I’ve tried various permutations to redirect an ASP to a sub-directory. It keeps failing because it seem to insert the domain as if it’s also a sub-directory of the root! Aaaargh!
Response.Status=”301 Moved Permanently”
So, using either:-
Response.AddHeader “Location”, “/NewSubDir/MyASP.asp”
OR
Response.AddHeader “Location”, “http://www.kinglet.co.uk/NewSubDir/MyASP.asp”
OR
Response.AddHeader “Location”, “/NewSubDir/MyASP.asp”
OR
Response.AddHeader “Location”, “/NewSubDir/”
The Browser URL changes to:-
http://www.kinglet.co.uk/www.kinglet.co.uk/NewSubDir/MyASP..asp
and I get a file or directory does not exist error.
Requested URL http://www.kinglet.co.uk:80/www.kinglet.co.uk/NewSubDir/MyASP.asp
Physical Path C:\Inetpub\vhosts\kinglet.co.uk\httpdocs\www.kinglet.co.uk\NewSubDir\MyASP.asp