SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IIS Custom 404 Page Gives 200 Response Code

    I'm working on a website that uses IIS and needs a custom 404 page created. I made 404.aspx and added the following code to my web.config file

    Code:
    <customErrors mode="On" redirectMode="ResponseRewrite">
    	<error statusCode="404" redirect="404.aspx"/>
    </customErrors>
    It does work (nonexistantpage.aspx shows the contents of 404.aspx) but when I check the header response code, I see a 200 instead of a 404 (a big SEO no-no). Any ideas on how I make it show the correct error response code?

    Thanks
    Last edited by ParkinT; Jan 3, 2013 at 12:19. Reason: Corrected Thread Title

  2. #2
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found the fix.. need to add the following code to the top of 404.aspx

    Code:
    <% Response.Status = "404 Not Found" %>

  3. #3
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,633
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    The better way is to use the errors bits under system.webServer if you are on IIS7 -- those will spit back proper http codes without adding it to the script.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •