Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 24 of 24

Thread: It's using 302 redirects for deleted products - How to use 404's?

  1. #1
    DanielR is offline Member
    Join Date
    Aug 2007
    Posts
    30

    Default It's using 302 redirects for deleted products - How to use 404's?

    Hi,

    We had a site that sold widgets, gizmos and doodads. We split this site up into three different sites.

    On the original site, we have deleted gizmos and doodads, and only have widgets now.

    However, all the previously indexed pages for gizmos and doodads are getting a 302 redirect to the product-not-found page when clicked on.

    These pages were not temporarily removed (which 302 is used for) and google is not dropping them from the index. How do I make these product pages return a 404 page instead of a 302?

    Much appreciated!
    -D

  2. #2
    ASPDNSF Staff - Eileen is offline Banned
    Join Date
    May 2008
    Posts
    43

    Default

    You can see the Custom 404 feature in our manual here.

  3. #3
    DanielR is offline Member
    Join Date
    Aug 2007
    Posts
    30

    Default

    I looked at the link you provided, but it's not doing 404's. It's doing 302's.

    1) Let's say Product 150 was deleted.
    2) The store now 302 redirects that page to /t-productnotfound.aspx

    I've checked the server headers with:
    http://www.seochat.com/seo-tools/check-server-headers/
    http://www.seoconsultants.com/tools/headers.asp

    Both are showing:

    #1 Server Response: http://www.mysite.com/p-645645613-widgit.aspx
    HTTP Status Code: HTTP/1.1 302 Found
    Connection: close
    Date: Mon, 30 Mar 2009 21:47:35 GMT
    Server: Microsoft-IIS/6.0
    X-Powered-By: ASP.NET
    X-AspNet-Version: 2.0.50727
    Location: /t-productnotfound.aspx
    Set-Cookie: ASP.NET_SessionId=lbxhjzqcxxpgqnncep3g0trg; path=/; HttpOnly
    Set-Cookie: SkinID=1; domain=mysite.com; expires=Tue, 30-Mar-2010 21:47:35 GMT; path=/
    Cache-Control: private
    Content-Type: text/html; charset=utf-8
    Content-Length: 140
    Redirect Target: /t-productnotfound.aspx


    I've tested this on version 7.1.1 and 8.0.0 and both are doing a 302 redirect when:

    a) A product has been deleted it goes to /t-productnotfound.aspx
    b) A category is deleted it goes to /default.aspx

    How can I get these to 404? I'd like them removed from Googles index, not temporarily redirected. Maybe I'm looking at something wrong?

    Any help is much appreciated!

    -D

  4. #4
    hunter0781 is offline Member
    Join Date
    Apr 2010
    Posts
    34

    Lightbulb soft 404s

    I'd like to reopen this thread....

    Anyone else having issues with deleted products being seen as 302 temporary redirects?

    Is my assumption correct that they should be 404's?

    Webmaster tools is telling me I have a soft 404 for http://www.soycandledepot.com/p-263-...oy-blocks.aspx which means it's still returning a response code of 200.

    How do I make these product pages return a 404 page instead of a 302?

    more info: http://searchengineland.com/google-w...04-pages-43748

    Thanks everyone!

  5. #5
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    In this case I would suggest setting the response status to 404 in the topic/driver code behind based off the topic name. Making the if statement code look something like this:
    C#/VB.NET Code:
    if (PN == "ProductNotFound")
    {
        
    Response.Status "404 Not Found";


  6. #6
    jsimacek is offline Senior Member
    Join Date
    Dec 2008
    Location
    Phoenix, AZ
    Posts
    373

    Default

    I believe you would be interested in our http://www.ecommercecartmods.com/p-1...torefront.aspx which allows you to setup ANY type of redirect (300,301,302 etc) to ANY page in the cart (categories, products, topics etc)!

    Very useful for maintaining SEO rankings!
    Jan Simacek - Compunix, LLC
    AspDotNetStorefront trusted Devnet Partner and Reseller since 2005

    AspDotNetStorefront Mods and Add-Ons at http://www.ecommercecartmods.com/
    - Searching, Filtering and Sorting (like cSearch, Dealer Locator, Price Ranges, Blog)
    - Reports (like Cart Abandonment and Net Sales)
    - Customer Experience (like Question/Answers)
    - Site and Data Management (like Entity Product Mapper, Bulk Updaters, Make/Model/Year filters)

  7. #7
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    I would also like to reopen this topic. Google is calling the 302 redirects a "soft 404" error whenever we removed a product that is indexed (happens all the time). It seems like a simple fix if we just knew where to make it. The recommended commercial solution would probably work but $300 seems a little steep for a 5 minute fix.

    Does anyone know how to fix this problem?

    Thanks,
    Tom

  8. #8
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    does the suggested change I have posted for driver.aspx.cs not work for you then?

  9. #9
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    I didn't see the file name, driver.aspx.cs if your first post and didn't know which file to look for. I'll look at that file and post if I can make it work.

    Thank you,
    Tom

  10. #10
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    mmcgeachy,

    Thanks for the help. I tried your suggestion but it didn't work but most likely I didn't do it correctly. I'm not an Aspdnsf expert.

    I read the driver.aspx.cs file and didn't see an obvious place for the code. Since PN was defined inside an if statement checking for Topic1.TopicName.Length equal to 0 I put your code suggestion below where PN gets set. It didn't break anything but the response was still 302.

    I have a couple of general debugging questions. When I change a .cs file, is there anything I have to do to force a recompile?

    Are there any programming tricks to know if the code is getting executed on a live site? Is there a way I can display a message or write something to the output page to know the code is getting executed and maybe write the value of PN? I know these are pretty basic debugging questions but again, I'm really not very familiar with working inside Aspdnsf. Any help is really appreciated. Whenever I have to make changes I'm flying blind mostly.

    Thank you,
    Tom

  11. #11
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Quote Originally Posted by Tom Cox View Post
    mmcgeachy,

    Thanks for the help. I tried your suggestion but it didn't work but most likely I didn't do it correctly. I'm not an Aspdnsf expert.

    I read the driver.aspx.cs file and didn't see an obvious place for the code. Since PN was defined inside an if statement checking for Topic1.TopicName.Length equal to 0 I put your code suggestion below where PN gets set. It didn't break anything but the response was still 302.
    Try the code after
    Code:
    AppLogic.CheckForScriptTag(PN);
    Keep in mind that the topic content will still show up so you will need to be checking the HTTP status in firebug, fiddler or something similar. So don't be looking for your regular 404 page to show up. Also lets be safe and make sure casing isn't getting you by trying this if statement instead
    Code:
    if (PN.ToLower() == "productnotfound")
    {
        Response.Status = "404 Not Found";
    }

    Quote Originally Posted by Tom Cox View Post
    I have a couple of general debugging questions. When I change a .cs file, is there anything I have to do to force a recompile?
    What kinda of .cs you are editing matters in this case. A .aspx.cs it should be just a matter of viewing the .apsx page after the file has been saved to see the changes. As .cs with no other extension and is not in the App_code folder will require compiling. It will also most likely require updating DLLs on the live site also.

    Quote Originally Posted by Tom Cox View Post
    Are there any programming tricks to know if the code is getting executed on a live site? Is there a way I can display a message or write something to the output page to know the code is getting executed and maybe write the value of PN? I know these are pretty basic debugging questions but again, I'm really not very familiar with working inside Aspdnsf. Any help is really appreciated. Whenever I have to make changes I'm flying blind mostly.

    Thank you,
    Tom
    As for knowing when code is executed writing output is the essayist way I know of to check to see if code is being reached. As for writing the output doing a Response.Write or adding a label to the .aspx page and then setting the label.text will show output.

    Hope that helps.

  12. #12
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    mmcgeachy,

    Thank you very much. That should help.

    I did put the code in the place you suggested and yes, I checked the header and the response was 302. However, I'm never quite sure of what I'm doing here in Aspdnsf. I will try it again today and try to verify that the code code on the driver.aspx.cs file is actually executing and see if I can figure out what value is in the PN variable. I tried "PageNotFound" and all lower case but it didn't work.

    I will try response.write and try to figure out how to add a label. These are good things for me to learn anyway, because I have this same type of problem whenever I try to make a change.

    I will reply back after I try these things. Thanks again for your help. I really appreciate it.

    Tom

  13. #13
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    OK, I've learned a little bit but don't have it working.

    I inserted this code below AppLogic.CheckForScriptTag(PN);

    if (PN == "productnotfound")
    {
    // Response.Write(PN);
    // Response.Status = "404 Not Found";
    }

    When I uncomment the Response.Write, I get "productnotfound" written at the top of the t-productnotfound.aspx page as expected.

    When I uncomment the Response.Status line, I get a "messed up" page in return. It has elements from my page but lots of stuff is missing and it's not formatted well at all. I suspect that some important code is not getting executed after the status is set.

    Also, when checking the header, it is still giving a 302 response code on the messed up page.

    So I learned a little bit about debugging Aspdnsf but I'm wondering if maybe this isn't the right place or the right technique to get the desired response.

    Is there maybe another place further down in the logic path to try this?

    Thank you,
    Tom

  14. #14
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Sorry for the late reply. I wouldn't of thought the position mattered for setting the status code but it is worth a try. There are two places to try after the
    Code:
    CheckForRedirect(Topic1.TopicName);
    statement and after the this if statement
    Code:
    if (m_topicid > 0)
    in other words the the line line of the if statement of
    Code:
    if (Topic1.TopicName.Length == 0)
    .

  15. #15
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    No, I meant too early in the overall process, not too early in the file. It seemed to work, when I did some testing but it caused the page to not render correctly and at some point later in the process the status was set to 302. I think setting the status to 404 in the driver.aspx.cs file messes up some later processing. I don't have a good understanding of the order of processing but it appears that something happens later in the process that gets messed up by changing the status code. Does that make sense?

    When I put in a response.write(pn) it clearly wrote "productnotfound" at the top of the page. But as soon as I added Response.Status = "404 Not Found"; the page didn't render correctly (and the final status was 302).

    Thanks

  16. #16
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Hmm what is the page URL look like when you are testing? Is it t-productnotfound.aspx or something like p-1-name.aspx? If it is not p-1-name.aspx I think I found the issue. showproduct.aspx.cs used to do a Response.Redirect in older versions instead of Server.Transfer.

    To fix this replace the code below in showproduct.aspx.cs

    Code:
    Response.Redirect(SE.MakeDriverLink("ProductNotFound"));
    with

    Code:
    Response.Status = "404 Not Found";
    Server.Transfer("driver.aspx?sename=ProductNotFound");
    return;

  17. #17
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    mmcgeachy,

    I really appreciate your help on this.

    I checked and discovered that when I implemented the drivers.aspx.cs change previously, the resulting page (that was messed up) contains domain/p-number-removed-product.aspx in the address bar. So based on your comment, it looks like your suggestion would not be expected to work but I tried your change anyway.

    I made the change first to showproduct.aspx.cs. No errors occurred and when entering a non-existing product, I got the browser 404 page. (I didn't check the return code.) When I added the change to drivers.aspx.cs, I got the same messed up page (with the p-number.aspx in the address bar). It's hard to tell what page is trying to be rendered. I see just a few of our header and footer elements but no body to the page and formatting is all off.

    I'll look at the files more closely and try the change again later on today and report if there is any difference in results.

    Thanks again for your help on this. I'm sort of suprised that there aren't a lot of other people reporting this problem. It seems to originate from removing products (a normal function) where the page has been indexed by Google (or possibly where someone has posted a link directly to the removed page). I have worked hard to removed every error reported by SEOmoz which removed all the errors reported by GWT except these "soft 404's."

  18. #18
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    OK, I did more testing.

    I discovered that the badly rendered page only happens in InternetExplorer. It works much better in the four other browsers I tried. (poor IE)

    Using the code change in showproduct.aspx.cs, I can display a site template page and generate the 404 return code. The problem is the body of the page is blank. Plus of course, I get a garbage page in IE.
    When I fiddled with it to display the productnotfound page the return code reverted back to 302 again.
    I'm not sure if this result is better or worse than showing the productnotfound page along with the 302. I guess it depends on how much Google dislikes the 302.

    I will do more more testing and post the final code I use.

    Thanks again for the help.

  19. #19
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    which version of IE are you running? So far I haven't been able to reproduce your issue of odd rendering in IE in my testing.

    As for the blank issue it is hard for me to say for certain but my next question would be is the productnotfound topic blank or even there as a topic?

    Also If I had to guess why others haven't had the issue as much is version 9.3.1.0 has a fix for this issue. That fix uses PageNotFound.aspx instead of the productnotfound topic other wise both fixes are very similar. Therefore you could try doing a sever.transfer to PageNotFound.aspx instead to see if that works better for you.

  20. #20
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    Hi,

    I'm running IE 9. I tried signing out of the Aspdnsf admin site because I thought that might have affected it but no difference. I still got a badly rendered page.

    In all the other browsers, I get a blank "template" page. I see our headers, footers, navbar etc but the "content" section is blank. In the address bar it says http://our.domain.com/p-nnn-discontinueditem.asp so we are not actually getting our productnotfound page. But in any case, the productnotfound page is not blank and works nicely before I tried to make this change. The problem again was that it was giving a 302 which GWT complained about.

    I left it this way for a few days and now I'm getting warnings from SEOmoz about 404 pages. I'm beginning to wonder if I should 301 the deleted product pages to the productnotfound page (or to the category page if possible).

    I really need to upgrade to version 9 anyway but just don't have the time and money right now. This is another reason to do it.

    In the meantime, is there a way to deliver the pagenotfound page but send a 301 instead of 302 or 404?

    Thanks for the help.

  21. #21
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Quote Originally Posted by Tom Cox
    Hi,

    I'm running IE 9. I tried signing out of the Aspdnsf admin site because I thought that might have affected it but no difference. I still got a badly rendered page.

    In all the other browsers, I get a blank "template" page. I see our headers, footers, navbar etc but the "content" section is blank. In the address bar it says http://our.domain.com/p-nnn-discontinueditem.asp so we are not actually getting our productnotfound page. But in any case, the productnotfound page is not blank and works nicely before I tried to make this change. The problem again was that it was giving a 302 which GWT complained about.
    The only referance I could find with 404 status and IE9 talked about linking a htaccess file but since we don't use one I can't check for that. As for the blank content issue that definatly sounds like a blank topic to me but since I can't see things directly it is hard to say for certain.

    Quote Originally Posted by Tom Cox
    I left it this way for a few days and now I'm getting warnings from SEOmoz about 404 pages. I'm beginning to wonder if I should 301 the deleted product pages to the productnotfound page (or to the category page if possible).

    In the meantime, is there a way to deliver the pagenotfound page but send a 301 instead of 302 or 404?
    Yes changing to 301 is just a matter of changing the Response.Status and then adding the a header location (main reason to add the location header is you are saying there a new location for the url.) Which would be:
    Code:
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location", "url_here");
    Given the http status codes though I would lean towards giving a response of 410 since for deleted products since it is more accurate of a status message. Which would be:
    Code:
    HttpContext.Current.Response.Status = "410 Gone";

  22. #22
    Tom Cox is offline Senior Member
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    104

    Default

    OK, that seems to work well. I'm getting the ProductNotFound page, rendered nicely in all browsers and we're sending the 301 return code.

    Yeah, I guess 410 is more correct. Let me think about this. We'd like to retain any link equity we can but we want to be good "citizens" too.

    I'll run it like this for a few days and see if we get any warnings or errors in SEOmoz or GWT.

  23. #23
    dybcio is offline Junior Member
    Join Date
    May 2007
    Posts
    5

    Default soft 404's problem

    To mmcgeachy:

    I have similar problem with those soft 404's.

    Solution proposed by mmcgeachy is very neat but seems to have one problem: First server response from page showproduct.aspx will be 302 regardless.
    Then there is redirect to topic page t-productnotfound that will give 404 (after the mod proposed), so I'm not sure how Google will handle this.

    Tom to your help:
    put this mode after the line:

    AppLogic.CheckForScriptTag(PN);

    PN object is already declared and initialized at this point.

    Any ideas how to throw 404 from product page itself?

  24. #24
    dybcio is offline Junior Member
    Join Date
    May 2007
    Posts
    5

    Default

    I guess my browser just loaded first page of this thread, for some reason ;-)

    I got my question answered once I opened this forum on other machine, sorry for confusion.