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 Posted 2008-07-31 12:20

17 responses:

Laura Arguello
Laura Arguello 2008-07-31 12:43 AM #
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.
Ken Auenson, II
Ken Auenson, II 2008-07-31 1:06 AM #
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!
Mark Aplet
Mark Aplet 2008-08-10 3:56 PM #
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
Adam
Adam 2008-08-11 8:26 AM #
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.
Seb Duggan
Seb Duggan 2008-08-12 11:26 AM #
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]
Adam
Adam 2008-08-12 11:39 AM #
Seb, Excellent idea!
Mark Aplet
Mark Aplet 2008-08-12 2:03 PM #
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?
Adam
Adam 2008-08-12 2:28 PM #
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.
Rick Mason
Rick Mason 2008-08-14 12:42 PM #
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.
Seb Duggan
Seb Duggan 2008-08-21 12:01 PM #
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]
Josh
Josh 2009-07-07 3:50 PM #
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.
John Sieber
John Sieber 2011-02-22 5:11 PM #
Sorry to resurrect such an old post, but I'm wondering if you might be able to help me out. I'm trying to use these rewrite rules for mango blog running on Railo 3.1 and Apache for Windows 2.2. I have the following in my .htaccess file.

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]
Dan
Dan 2012-01-10 3:08 PM #
Hi

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
Adam
Adam 2012-01-10 3:15 PM #
Hi Dan,

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?
Dan
Dan 2012-01-10 4:33 PM #
Thanks Adam!! I previously restarted MySQL and even the server with no success.

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.
Adam
Adam 2012-01-10 4:42 PM #
Glad I could help. :)

Leave a comment:

Leave this field empty: