I am running CF10 on IIS 7.5 with URL Rewrite module installed.
All the rewrite rules work perfectly and ColdFusion is returning the correct pages. In order to get the page displayed in the browser I have to manually set the 'content-length' value in Application.cfc like this:
<cfheader name="Content-Length" value="#getPageContext().getCFOutput().getBuffer().size()#" />
Without this code the browser does not display the page. However, even though it is now displaying the page, it is not doing it correctly. The page never finishes loading fully and not all of the HTML content seems to be on the page.
I have tried to add a <cfflush> tag after setting the 'content-length' but it makes no difference. I don't understand why this is happening but I know that it has happened to someone else who was using htaccess: http://forums.devshed.com/coldfusion-development-84/page-not-finishing -loading-coldfusion-and-htaccess-bug-575906.html
Can anyone please help?
This was my thought as well, to try out an helicon product. They're currently promoting something called Ape for IIS 7+ users but I'm pretty sure its only the Rewrite function that I need so I'll try out ISAPI Rewrite
One thing that I don't understand is how to rewrite the ugly links into friendly links on the fly within the HTML?
In IIS Rewrite Module it has Outbound rules which looks at the <a> tag and if there is a link in there which matches a pattern that you specify, then it will change that link into a friendly link. At the same time you write an Inbound rule that resolved the friendly link into the fully qualified ugly link so that the correct page is displayed.
In mod_rewrite I only seem to be able to deal with resolving links. How do you get it to rewrite the ugly links that are within the HTML on my page into friendly ones?
Did moving to Helicon ISAPI Rewrite help anything? I would be surprised if it did. I used to use that, but had to ditch it and now use just the Rewrite module built-in to IIS 7.5. Why do you have to force the content length anyway? That seems like a big potential break point.
Also, I am not aware of a program that will re-write the existing links embedded in your HTML code, if that is what you're asking. Of course if those links are in a content field that you can manipulate with ColdFusion beforehand, then you can customize those links using CF however you want.
P.S. The IIS7 Rewrite module has example templates built-in that should show you how to craft a custom response to any scenario, or at least ge the ideas flowing. They are under the SEO section of the "Add rule" dialog. The "User-friendly" mapping should all give you ideas.
The problem is Outbound rule writing in IIS Rewrite Module. Outbound rules rewrite existing links in the actual HTML content before its sent to the browser and this is causing the page load problems. This has only come to my attention when I found out that Isapi Rewrite (mod_rewrite) does not support Outbound rule writing.
Can you explain what you mean by a content field?
Okay, I didn't know that. I'm surprised the IIS Rewrite is able to change the HTML code in your page before someone even clicks the link, wow. I don't use Outbound obviously.
Content field, as in if you are using a content management system, and the field in the database contains the entire "body" of the page, then maybe you could write some fancy ColdFusion code to rewrite (Replace/REReplace) things it found before displaying to the end-user.
ISAPI rewrite does not (can not) change the physical HTML code, but what it can do is convert the request into something else. For example we have links like this:
and in our rewrite rule file, we have:
RewriteRule ([^\?]*)/widgets.cfm$ $1/categorypage.cfm?id=100 [L,QSA]
RewriteRule ([^\?]*)/gizmos.cfm$ $1/categorypage.cfm?id=101 [L,QSA]
So that a request for http://www.ourdomain.com/widgets.cfm actually requests http://www.ourdomain.com/categorypage.cfm?id=100, so in other words, we have SEO friendly URLs like widgets.cfm instead of URLs with parameters (?id=) in them. That is how the URL is "rewritten" in this context. Both URLs would work, but we never expose the one with the parameters to the end-user. URL rewriting is an entire subject in its own right, and is not directly related to ColdFusion as it works with all server-side languages.
Solaced, can you give an example of the URLs you are working with, and what you need the outcome to be?
When developing a web application, you are naturally going to have ugly links because otherwise your IDE will not have a clue which files you are trying to link to.
But when the webpages are being served to the user, you want them all to be presented in user-friendly URLs.
How are you supposed to include user-friendly URLs within your webpage before they are served to the user? If you manually have to change these types of links:
<a href="http://mysite.com?article=1§ion=5">Article 1, Chapter 5</a>
into these type of links:
<a href="http://mysite.com/article-1/section-5">Article 1, Chapter 5</a>
then you will mess up your entire application. Links will appear broken when you try validate the site and the site may look a mess.
So how are people including user friendly URLs within their application code?
Solaced, I can put the friendly URLs in my HTML code and they work fine (with Helicon's ISAPI rewrite using the rules I pasted earlier), indeed that is the most preferable method since we clearly want the friendly URLs to be seen by the public.
I can put the long URL or the friendly URL in my source, and both work fine. Clearly I want the unfriendly URL to stay out of the Google index if possible (for SEO). The only time a friendly URL will not work is when the rewrite for it is removed.
By validate, I mean if you use an IDE like Dreamweaver and want to check for broken or ophaned links, then it will bring up lots of errors because the IDE won't be able to find the 'friendly/fake' URLs. Its probably not hard on a small site, but on a huge site it would be a nightmare to keep track of what links to where when the site is full of fake URLs before it has been uploaded to the web server.
Solaced, I've never used an IDE; I only code with notepad.
Orphaned links (and other link issues) are best checked with Google Webmaster Tools (GWT). There's a whole raft of tools that can help you there, and they are free. As DCwebguy says, there are literally dozens of tools for checking website links for 404 errors and redirects etc. Our e-commerce site has over 30,000 products and lots of links and we use GWT and Google Analytics to track visits and deal with errors etc.
On one project I wrote CFML code to check when a product 404'd and then either 301'd it to a new alternative page, or show a range of alternatives. This was useful for when a product name changed, which happens very frequently for us. There are many ways to deal with broken links both on-and off-site and you can automate and log a lot of it internally.