I am building a custom 404 response page for a proprietary CMS dedicated to auto/motorcycle sales. The problem I'm running into is that sometimes Google will index a page for a unit that was in the dealer's inventory, but has since been removed, so I'm building a custom 404 page for those instances. My problem is getting the redirect to happen while preserving the 404 status.
The page is written in classic ASP. Long story short, IIS redirects the 404 status to a custom ASP page which I am using to then direct to my 404 page... the idea is that it will display my page only if the 404 comes from a piece of missing inventory and then behaves normally for other pages.
Here's the code that worked in Chrome after days of trying to sort it out:
<%
Response.Status = "404 Not found"
%>
<script language="JScript" ruant="server">
window.location = window.location.origin + "/src/xInventory404.asp";
</script>
<%
Response.End
%>
The problem is this doesn't work in Firefox or Internet Explorer 11 unless I remove Response.Status
, but if I do that I lose the 404 status. I can't just use a Response.Redirect
because it will lose the 404 and insert a 302 which I don't want for SEO purposes. I have also tried Server.Execute
and Server.Transfer
, neither of which worked even in Chrome.
I've been going in circles with this for a couple of weeks now and nothing I've seen on the web has helped so I thought I'd see if anyone here has another idea I can try. Anyone have any thoughts or suggestions?
Ok, so this ended up being a two-fold issue... the issue with Firefox was because I had <script language="JScript">
, changing that to <script language="JavaScript">
fixed my problem there... per John's comment, I removed runat="server"
from the mix, and it would seem the combination of those two things was the secret sauce here.
IE 11 was trickier... turns out the problem wasn't actually my code. IE has a setting to show friendly http errors, when I unchecked that option it also started to work. There's really nothing I can do about client side browser settings so that's kind of a wash, but at least I know what's causing it... and at this point the number of people still using IE 11 should be relatively small so I'm OK with it.
Thanks again for the insights, it really helped to have some different avenues to think about instead of remaining stuck in the circular thinking that brought me here in the first place.