Forum Moderators: open

Message Too Old, No Replies

404 not redirecting

windows 2012 IIS

         

dstiles

9:42 pm on Dec 11, 2014 (gmt 0)

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



Never had a problem on previous windows servers so I assumed this was working after I changed from 2003 to 2012, but today I needed a rather more complicated redirect and found the custom 404.asp I've always relied on is simply not being run at all.

I've set (and checked!) in errors for any file-not-found to go to /404.asp which in turn does a few basic checks before admitting defeat and issuing a 404; checks such as is the extension requested .html from an old site link instead of the newer .asp, for example.

I suspect there is something that needs setting in addition to the 404 error handler but find it I cannot. :(

The code still works fine on an old server.

aakk9999

12:17 am on Dec 12, 2014 (gmt 0)

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



We use .NET IIS 8.5 on Windows Server 2012

You are mentioning 404.asp, are you running .NET or the classic asp?

Do you have something like this in your web.config:

<httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" path="/404.aspx" prefixLanguageFilePath="" responseMode="ExecuteURL" />
</httpErrors>

In your 404.aspx, after your checks, do you have something like this to issue 404, before you output anything else:

<% Response.StatusCode = 404; Response.Status = "404 Not Found"; Response.End(); %>

dstiles

8:09 pm on Dec 12, 2014 (gmt 0)

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



Thanks! I'm nominally running Classic, but .NET keeps cropping up.

There is no web.config that I can easily find except in special redirect folders I had to install on some sites to take 301 redirects for a number of secondary domains.

I set the server-level 404 error handler to /404.asp and that has filtered down to each site as I installed them, so I assumed that if there were a 404 error it would run /404.asp as it always has done before. Surely if a web.config file were required for each site it would have been installed automatically?

The 404.asp files are somewhat akin to your final line but have several lines of code preceding it to determine whether to issue a 404 or redirect to a suitable page. This has been virtually unaltered for 15 years or more.

As with most MS "advances" in web servers over the past 20 years, I've found them confusing and to a large extent unnecessary: the 2003 301 redirect and 404 error handling worked fine as they were.

Ocean10000

9:57 pm on Dec 12, 2014 (gmt 0)

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



Think of the web.config in the folder as a override of the base settings, much like a apache htaccess file does. It's not required to be there but, it does allow you to make changes on a site by site bases, from the server defaults.

dstiles

8:38 pm on Dec 13, 2014 (gmt 0)

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



Yes, I worked that out soon after I began 2012. My complaint is that it did not set up 404 to work as it should. In my book, a change to anything should be effected, not ignored. :(

I'm still cursing the guy who, 20 years ago, convinced me to use IIS. I was quite happy at the time running perl under unix. :(

dstiles

8:49 pm on Dec 13, 2014 (gmt 0)

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



aakk9999 - I tried your code as web.config in a site's public_html, changing aspx to asp and adding a top line of...

<?xml version="1.0" encoding="UTF-8"?>

It immediately behaved in the same way as before, even after restarting the site. :(

dstiles

10:03 pm on Dec 15, 2014 (gmt 0)

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



Ok, I think I have some basic working code. The full code should be:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" path="/404.asp" prefixLanguageFilePath="" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>

(There is / can be other coding inside the system.webserver section as well.)

This ALMOST does it: I now have to persuade this particular site to redirect according to the /404.asp code and not just redirect to the home page.

I think this should be in the system's web.config but I'm (again!) having trouble reading it - a persission problem. I overcame it once before but forget how I did it.

By the way, if you get an error in web.config the whole site dies! Wonderful bit of coding, that. Thanks, MS. :(