Welcome to WebmasterWorld Guest from 35.173.47.43

Forum Moderators: ocean10000

Message Too Old, No Replies

Problem with 301 redirect , Page redirects before script executes

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

New User

10+ Year Member

joined:Oct 12, 2006
posts: 5
votes: 0


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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 13, 2005
posts:1078
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


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.

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

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11823
votes: 236


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".

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

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members