Avatar of JDEE8297
Flag for United States of America

asked on 

Setting up a 404 redirect

We are in the process of redesigning our site and as with all sites you want to be able to keep the link value of the old links, and do a 301 redirect where appropriate, one of the pages on our site that I need to be able to do this with is the product details page. Depending on what values are passed into it, I need to be able to do a 301 redirect on it....no problem on that end. However, what I need to be also to do is if we don't ahve a product on the site anymore, then I need to be able to redirect them to the product index page and generate 404 in the process.

So that Search engines will remove the link from their index and give the user the opportunity to find the product or alternative to the product they were originally looking for. The problem is that I can generate the 404 status code, but I still end up doing a 302 redirect.

If I take the redirect out that I have in the code sample, then it just stays on the page and nothing happens, the 404 status code is generated but the page never redirects the way I thought it would. I have not done asp for a while, so any help on this would be appreciated. :)
sub RedirectPage(intType)
    'Local variables
    dim strStatusMsg
    dim strRedirectUrl
    'Check to see what redirect type is being done
    select case intType
        case 301
            strStatusMsg = "301 Moved Permanently"
            strRedirectUrl = cstrServerDomain & arrRecs(0,0)
			'Redirect page
    response.Status = strStatusMsg
    response.AddHeader "location", strRedirectUrl
        case 404
            strStatusMsg = "404 Not Found"
            strRedirectUrl = cstrServerDomain & "products"
			'Redirect page
    response.Status = strStatusMsg
			response.AddHeader "location", strRedirectUrl
			response.redirect (strRedirectUrl)
    end select
		response.write strStatusMsg
	response.write strRedirectUrl
end sub

Open in new window

Web Languages and StandardsASP

Avatar of undefined
Last Comment

8/22/2022 - Mon