Even prettier SES URLs in Mango
July 31 2008 by
Adam
Tonight I installed Ionic's ISAPI Rewrite filter on my server and set it up for this domain. I've always been a fan of the www-less URL, so now you don't have a choice — I'm redirecting you here. In addition to that, I'm making urls like /page.cfm/projects/burnt-mango accessable as /page/projects/burnt-mango. I even took it a step further and redirect you to the new pretty format from the old ugly format, in case there are any errant URL's going around.
The first thing I had to do, once I got the ISAPI filter installed and running, was to define my rewrite rules:
###### force removal of www. prefix on all requests
RewriteCond %{HTTP_HOST} www.fusiongrokker.com(.*) [I]
RewriteRule ^/(.*) http://fusiongrokker.com/$1 [I,R=301,U,L]
This takes care of getting rid of "www." from the URL.
###### Mango Blog stuff
#redirect old url's to their new fancy url's
RewriteRule ^/post.cfm/(.*)$ /post/$1 [R=301,I,U]
RewriteRule ^/page.cfm/(.*)$ /page/$1 [R=301,I,U]
RewriteRule ^/archives.cfm/(.*)$ /archives/$1 [R=301,I,U]
RewriteRule ^/author.cfm/(.*)$ /author/$1 [R=301,I,U]
These will redirect you from the old page.cfm/page-name format to the new page/page-name format.
#standard mango rewrites
RewriteRule ^/post/(.*)$ /post.cfm/$1 [I,U,L]
RewriteRule ^/page/(.*)$ /page.cfm/$1 [I,U,L]
RewriteRule ^/archives/(.*)$ /archives.cfm/$1 [I,U,L]
RewriteRule ^/author/(.*)$ /author.cfm/$1 [I,U,L]
And lastly, these rewrite the new page/page-name format as page.cfm/page-name so that Mango can still interpret them correctly.
Notice that for all of my redirects ([R] flag) I'm using R=301. 301 is the status code for Moved Permantently, rathern than the default of 302, Moved Temporarily. This will tell search engine spiders and other smart things to update themselves; as well as preserve any PageRank that the old URL might have had. The L flag stands for "Last" and indicates that no further rules should be processed after this one is matched. In this case, I'm using it to prevent circular references, where going to page/page-name rewrites as page.cfm/page-name, which redirects to page/page-name which rewrites as… yeah.
Update: As suggested by Seb Duggan in the comments, I've combined the above rules into these two simple lines:
#redirect old url's to their new fancy url's
RewriteRule ^/(post|page|archives|author).cfm/(.*)$ /$1/$2 [R=301,I,U]
#standard mango rewrites
RewriteRule ^/(post|page|archives|author)/(.*)$ /$1.cfm/$2 [I,U,L]
After the rules are in place, we have to tell Mango how to output URLs in the new format. It uses a special file called config.cfm which contains your blog settings.
These are just the relevant settings, of course. They should use the format that you want the user to see the URL as, because this is what Mango uses to format its links.
I keep finding more and more reasons to love Mango. This is just another one of them.
Posted in Mango |
12 comments



That's a great guide.
I always recommend people to use URL rewriting if they access to it (ie: you almost always can use them if you run Apache). It makes cleaner URLs and any migration migration easier.
Woot!
Thanks for the informative post.
Since you are doing all the legwork, I may have to check this out.
Oh, and I am liking the look of the blog, if I haven't said that already!
Any reason to direct users to a non www domain instead of the www domain? I understand the SEO benefits of not splitting your traffic but not sure there are any for going with or without the www
Mark, for me it's just personal preference.
Normally I would just support both. But since I have the capability, I'll forward users to non-WWW, and (as you said) not split my page rank between the two.
It's something I've already done for my website, but kudos on posting the tutorial...
If you want to make it a bit neater, you can condense each of the sets of 4 rules into a single rule:
#redirect old url's to their new fancy url's
RewriteRule ^/(post|page|archives|author).cfm/(.*)$ /$1/$2 [R=301,I,U]
#standard mango rewrites
RewriteRule ^/(post|page|archives|author)/(.*)$ /$1.cfm/$2 [I,U,L]
Seb, Excellent idea!
Hey Adam, I purchaed ISAPI Rewrite 3 http://www.helicontech.com/isapi_rewrite/ but your rules don't work for me. I have had issues getting mango to work correctly also. Have you had any issues with iconic's rewrite filter? I may have to ditch the $99.00 ISAPI 3 in favor of the free rewriter. Any words of wisdom before making any changes?
Mark, the documentation for Ionic's rewriter is a little vague/confusing regarding exactly how to set it up; but once you've got it running, it's pretty straight forward.
In particular, I thought I would be clever enable it for all of my websites by making my change on the "Websites" folder, rather than at the individual website level. That seemed to have no effect, so I went back and did *exactly* what the instructions said, and it worked for me. The only downside being that you have to copy the dll & ini files, and go through the setup for every website you want to use it.
A small price to pay, imo.
I tried this with ISAPI Rewrite 3 and had no luck either. I don't have the option of changing at this point. If anyone gets this working I'd love to know.
Rick, hop on over to my site, I have it working with ISAPI Rewrite 3.0 now. The code is only slightly different from Adams. I have code samples there. Here is the link:
http://www.visual28.com/articles/friendly-urls-with-isapi-rewrite
Re: ISAPI Rewrite 3
I'm using that on my site, and it works.
However, chances are that you have the rule:
RewriteBase /
at the top of your file. If you do, then you'll need to remove the leading / from the rules, e.g.:
RewriteRule ^(post|page|archives|author).cfm/(.*)$ /$1/$2 [R=301,I,U]
I'm feeling like a total idiot today. I cannot get this to work for me no matter what I try. Anyone feel up to helping me out? My blog (for now at least) is here: http://www.joshsager.com/blog/
I have ISAPI_Rewrite installed and I know it works, but I can't get the rules right at all. I just want to remove the .cfm part from the URLs.