Friendly URL's for Mango Blog with ISAPI_Rewrite 3.0
If you have visited my site visual28.com in the last few days you might have noticed a lot of errors. I hope that is all behind me now. Please let me know if you do encounter any errors that I have not fixed. The cause of all this chaos was due to a lethal combination of ISAPI_Rewrite and IISPassword. Both programs were overwriting the .htaccess file and causing major headaches.
Even though I wanted to pull my hair out, I was able to correct the problem and learn a great deal about ISAPI_Rewrite in the process. Previously, I had a cobbled together system that did not work correctly for all pages. With some help of Adam Tuttle of fusiongrokker.com I was able to get my url rewrite rules all fixed up. Turns out, I had the rules correct but the order that the rules are in makes a difference in how urls are rewritten.
If your interested in using ISAPI_Rewrite to make your urls friendly to both humans and search engines. Here is what I was able to put together.
Adam has an excellent tutorial on creating "Even prettier SES URLs in Mango" He uses the free ISAPI Rewrite filter by Iconic. It's free but a pain in the ass to install. Each file has to be placed into every site needing the rewrite filter. Thats too much work for me, so I opted for the $99.00 ISAPI_Rewrite 3.0 because it's a piece of cake to install and it's automatic for all sites within IIS. Thats something I really appreciate.
The first thing to rewrite is the domain name. I prefer to use the www.visual28.com domain name as opposed to just visual28.com. I cannot find any reason to support why search engines would prefer one format over another. I don't think it matters at all. That being said, I based my decision on human behavior. Most people (non-technical) think the domain names have to have a www in them to work. So why not default your domain to a www domain.
So to force the use of the "www" prefix in the domain we came up with this solution.
#301 redirect to www domain
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http://www.%1%2 [R=301,L]
The only part I really understand here is that we are doing a 301 redirect to the www site, which is what we want to do. The 301 redirect tells search engines that the page has moved permanently to a new location. This 301 redirect is essential to maintaining whatever search ranking you already had on your site
The next thing to do is take care of the URL rewriting for all the other pages in Mango. This is a pretty straight forward rule however I goofed up when I got the rules out of order. I had no idea that it makes a difference. But again thanks to Adam he got me pointed in the right direction which ultimately lead to this solution.
#Mango Blog URL Rewrites
RewriteRule archives/(.*) archives.cfm/$1 [I,U,L]
RewriteRule page/(.*) page.cfm/$1 [I,U,L]
RewriteRule articles/(.*) post.cfm/$1 [I,U,L]
RewriteRule author/(.*) author.cfm/$1 [I,U,L]
The important thing here is that the archives rule must come before the page rule or mango will freak out and throw an error saying that it is looking for page 1.
The last thing to do is update the mango config.cfm file located in the mango web root. This file tells Mango Blog how to output the urls. Once you upload the new config file it may be necessary to go to the admin and reload the configuration.
<entry key="searchUrl" value="archives/search/"/>
<entry key="postUrl" value="articles/{postName}"/>
<entry key="authorUrl" value="author/{authorAlias}"/>
<entry key="archivesUrl" value="archives/"/>
<entry key="categoryUrl" value="archives/category/{categoryName}"/>
<entry key="pageUrl" value="page/{pageHierarchyNames}{pageName}"/>
Hopefully all went well and you see your new friendly URL's. Hopefully this tid bit of information will help you get ISAPI_Rewrite up and running on your Mango blog and not have to deal with the headaches that I had to. Now that I have it figured out I cannot wait to do the same for all of my other blogs.


Glad you got it worked out, Mark! Glad I could help, too. :)
Thanks for posting this Mark. Adam pointed me at this post and everything worked great.
Only thing I noticed is you've changed "post" to "articles" in your rules which I didn't do right away. I just took the .cfm off the postUrl entry and it took me a few minutes to figure out the change.
Yeah I changed it to "articles" to make it more descriptive for non-technical people. It could be anything really. I should have mentioned that in my write up.