Forum Moderators: open

Message Too Old, No Replies

Problem with 301 redirect , Page redirects before script executes

         

benu aggarwal

6:45 pm on Apr 9, 2009 (gmt 0)

10+ Year Member



We have a few 404 errors in webmaster crawl and these are URL's created by referrals. We want to drop the referrer and do a 301 redirect on these URL's. Before doing the redirect, we need to do two things
1. Dump the cookie on the user. This part works fine
2. Execute all the scripts on the page.
3. 301 redirect to the homepage

We are not able to execute all the scripts on the page and then redirect. The 301 redirect happens before the script executes.

Is there a better way to do this?

carguy84

2:52 am on Apr 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What scripts are you talking about, Javascript or ASP/ASPX?

If it's Javascript, it will never load as the ASP/ASPX gets executed before anything is sent to the browser.

If it's ASP/ASPX scripts, you just need to have the redirect be after whatever else you want to execute.

g1smd

9:29 pm on Apr 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Code the 301 redirect as the very last thing to happen in the ASP script.

Once the redirect is sent, the browser is already heading off to the new URL.

There is practically no way for any Javascript to be actioned in the browser.

phranque

9:09 am on May 1, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



according to the protocol,
the "301 Moved Permanently" Status Code Definition [w3.org] states:
... the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).

most browsers seeing a 301 header would never render any content and instead would request the new "Location".

g1smd

11:59 am on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can dump a cookie before the 301 redirect is invoked, but there will be no content delivery (including JavaScript).