I have a ColdFusion (CF10) custom 404 handler for IIS (IIS 7.5, Win2K8 R2) that checks for "friendly urls", and if found returns the appropriate content. For example:
http://www.domain.com/user1 returns the same content as http://www.domain.com/?user=user1
It appears that IIS is only returning the top x (1000?) bytes for the page, and is also returning the 404 error. Is it possible force IIS to return a 200 OK? I tried adding:
<cfheader statusCode="200" statusText="OK">
to the 404 handler, but IIS is still returning the 404 error to the browser.
As a follow up question, is there a better way to do this? Can I use the URL Rewrite module? I thought this might be difficult because I think it only matches patterns in the URL, and friendly URLs could also match folder names, which may exist. That's what my 404 handler checks against.
You are touching on a couple of different things here. For the first part, SEO friendly URLS, I would say that IIS Rewrite is the tool to use. No need to have ColdFusion waste processing time on these. Let IIS Rewrite handle it and only pass the meaningful stuff to ColdFusion. You can find thousands of examples if you Google for something like iis rewrite for seo friendly urls.
For the second part of your question, handling 404 errors. I would suggest that you do not want to return a 200 OK
status code for these. They are 404's after all. Instead have your 404 handler (if possible) redirect to the new (or wanted) page by issuing a 301 Moved Permanently
status code. Not only will it push your visitors to the correct page but it will also keep the search engine bots happy. If you do not have a page to redirect your visitor then by all means return a proper 404 Not Found
status code. Perhaps including some links to your site's most common pages on the resulting 404 page. Again, Google is your friend, search for something like 301 redirect for 404 errors for examples. Remember, for a 301 redirect you also need to include the new location (for the redirect). Like so:
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="http://www.newlocation.com">
As an aside, you did not really mention how you have your 404 handling setup in IIS and/or ColdFusion. These can be setup individually or can be setup to work together (i.e. your IIS 404 handler can point to your ColdFusion 404 handling template). That is how I usually set up my servers. This gives you the ability to log, email, redirect, etc. all of your 404 errors.