I would like to return a 404 status code for every single request to a website. I still want to deliver a page of content, but I want the status code on every single request to be 404. (It's weird, I know, but there's a specific reason...)
I know I could do with this an HTTP Module or an OWIN pipeline, but I'd like to do it without writing or deploying code, if possible. However, this is a very weird situation, so I'm not sure if this is possible.
Can I set this from the web.config?
As lex says, we couldn't return the right content page with 404 error status.
Here is a workaround, we could try to use custom error page to achieve your requirement. If it should return 404 error, you could redirect the page to custom error page. But you should use the url rewrite to redirect all the pages to a not existed page.
Details about how to use custom error page in IIS, you could refer to this article.
Details about how to use url rewrite, you could refer to this article.
Related
I am creating a SEO Audit tool using NodeJS. I want to check if a URL has setup a custom 404 page or not. How can I check ?
I have analysed the response for both custom 404 page and default one both return same content-type and response headers. Both return HTML content only so how can I decide if it is a custom 404 page or not.
If this is very important for you to know (maybe you are selling custom 404 pages), you'll need to examine the HTML returned by the request.
Many popular servers, such as tomcat, iis, and apache return a standard 404 page that you should be able to recognize. Same thing with frameworks such as django or rails. You could build some logic that compares 404 results with the "fingerprints" of a known population of default 404 pages.
For example certain versions of tomcat have a title on their error pages that looks like this:
<title>Apache Tomcat/7.0.50 - Error report</title>
If you see something that looks like that you can be pretty sure that you are dealing with the default tomcat error page.
There are machine learning techniques that can probably do this for you without needing to compile a library of 404 page fingerprints (similar to filters that distinguish spam messages from legit ones).
I have a classic asp web application in which I've created a custom friendly 404 page. Also within that page, I have logic to email me the 404 info so I can check it out as to why it happened.
One of the pieces of info I email to myself is
Request.ServerVariables("HTTP_REFERER")
As I understand it, it should tell me the origin of the 404, ie. the page which is making the request to the file that doesn't exist.
However, I get notifications where the Referer is referencing a page in my site that doesn't exist in the first place. How can this be? Am I pulling the wrong ServerVariable? Is someone trying to do some cross site scripting?
I'm currently using customErrors, and I would like to use the recreate option, always.
This currently works for URLs such as
mysite.com/asdf
My custom error page loads as this URL:
mysite.com/asdf
However, this is not working for URLs such as
mysite.com/asdf.aspx
My custom error page loads as
mysite.com/mycustomerrorpage.aspx?errorpath=/asdf.aspx
This is handled by IIS as a 302 redirect to the error page above with a status of 200 when it loads.
What I'm trying to accomplish: I want the user to receive an http status of 404 (or respective status code), and I want the page to recreate always (regardless of extension or lack of extension). I do not want a 302 redirect from IIS, and I do not want the custom error page to return as a 200.
I'm new to IIS - This seems like it would be a basic thing, but I'm having more troubles than I would've guessed :)
Thank you in advance for any assistance!
Without having a url rewriter such as ISAPI_Rewrite available, is it possible to achieve the following:
I would like a user to browse to http://www.jjj.com/directory where /directory does not actually exist. IIS transfers the user to not-found.cfm.
At this point I can serve index.cfm i.e. http://www.jjj.com/directory/index.cfm.
The url will display just fine and the page loads even though the directory or index.cfm doesn't exist. However I'd like to be able to not have index.cfm in the url.
Ideal:
Page Request to http://www.jjj.com/directory
IIS loads not-found.cfm as the default 404 errorhandler.
Not found strips the CGI.query_string and uses cfswitches to funnel the user to the appropriate controller function. May use onMissingTemplate?
The page request never changes in the URL and the page loads transparently the user with 200 OK status
If a user requests http://www.jjj.com/directory/index.cfm I would 301 redirect to http://www.jjj.com/directory
Current:
Page Request to http://www.jjj.com/directory
IIS loads not-found.cfm as default 404 error handler.
Not found strips the CGI.query_string and uses cfswitches to funnel the user to the appropriate controller function.
The page request changes to http://www.jjj.com/directory/index.cfm with a 200 OK status
You're asking how to cut something but telling us you're not allowed to use a knife or anything resembling one.
Here's my only clever idea using onMissingTemplate().
GET /directory/
-> 404.cfm
-> <cfinclude template="#cgi.script_name#/special.cfm" />
-> fires onMissingTemplate() where you ignore the "special.cfm" bit and just use the rest of the requested path to figure out what controller to wire up to.
This is a kludgy hack, though, so I would try to avoid it myself. Maybe if you explain why ISAPI Rewriting isn't an option, then we might be able to help further.
You can tell IIS to have 404 and 403 errors execute a custom URL on your site (such as /urlhandler.cfm).
Then, you can parse the 'cgi.query_string' and route the application anyway you desire using cfinclude to simply include the correct 'template.cfm', or, you can reformat the input your framework is expecting, or, use a project like http://coldcourse.riaforge.org/.
Just one note, IIS will give you a URL that looks like this: '404;http://yoursite.com/the/url/you/wanted/to/route'.
Is IIS7 on the approved list of software? That can get you native url rewriting and side-step the whole issue.
Second option -- my CFM voodoo is rusty, but I think you can setup IIS6 to look for a CFM page (like you are doing) but then step in at the application level and do the url rewriting/repointing before it actually hits the 404 page.
Another way around it -- find an ISAPI url rewriter that is, say, under the MIT license. Build your own copy. Then have them install that as part of your software package.
Is there any means to track where within code a 404 error is handled?
We have a site that we have taken over that doesn't seem to be reacting as expected.
We have changed the IIS custom errors page to point to the new page we would like but something seems to still be redirecting it to the old 404.htm file in the root of this site. We have not been able to track down where or why this happens.
Any suggestions on how we might find the referring logic?