Even prettier SES URLs in Mango
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 accessible 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 Permanently, rather 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.
<node name="blogsettings">
<map>
<entry key="searchUrl" value="archives/search/"/>
<entry key="postUrl" value="post/{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}"/>
</map>
</node>
These are just the relevant settings, I've left the rest out for brevity. 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.
in Mango | 17 Responses 2008-07-31 00:20

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.
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!
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.
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]
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.
http://www.visual28.com/articles/friendly-urls-with-isapi-rewrite
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 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.
RewriteEngine on
RewriteBase /
RewriteRule page.cfm/(.*)$ page/$1 [R=301]
RewriteRule post.cfm/(.*)$ recipe/$1 [R=301]
RewriteRule archives.cfm/(.*)$ archives/$1 [R=301]
RewriteRule author.cfm/(.*)$ author/$1 [R=301]
RewriteRule page/(.*)$ page.cfm/$1 [L]
RewriteRule recipe/(.*)$ post.cfm/$1 [L]
RewriteRule archives/(.*)$ archives.cfm/$1 [L]
RewriteRule author/(.*)$ author.cfm/$1 [L]
The bottom set of rules are working perfectly and after configuring the new urls within mango the site is using the SES urls. I'm unable to get the first set of rules working that are supposed to redirect the user who enters the blog using the old urls to the new. Any ideas how I could get this to work? I also tried the following to see if it would help:
RewriteRule ^page\.cfm/(.*)$ page/$1 [R=301]
RewriteRule ^post\.cfm/(.*)$ recipe/$1 [R=301]
RewriteRule ^archives\.cfm/(.*)$ archives/$1 [R=301]
RewriteRule ^author\.cfm/(.*)$ author/$1 [R=301]
I am using MangoBlog 1.6 and have read elsewhere that you also need to change the urls inside the settings table - which I have done. I have also added the following to my config file as you suggested.. <node name="blogsettings">
<map>
<entry key="searchUrl" value="archives/search/"/>....
</map>
</node>
However, none of this seems to make any difference and MangoBlog is still generating urls such as post.cfm/hello-world, rather than post/hello-world
I have done the obvious restarts, etc. Please can you give me some advice. I am using IIS7 and Windows server. Many thanks
I don't think the settings file is necessary any more, it should all be based on the database settings. I imagine all that's necessary is to use the "reload configuration" button on the cache tab of the admin after updating the database.
What exactly have you restarted?
I just reloaded the configuration as you suggested above and it worked straight away!... Can you tell i'm new to mango blog! :)
Thanks again.