URL rewriting for Mango Blog with IIS 7.5 and Apache 2.2
I recently set up url rewriting for Mango Blog on both IIS 7.5 and Apache 2.2. I followed the excellent guide by Adam Tuttle, but experienced a few issues along the way, so I decided to add a post that may prove helpful to someone else down the road.
The first server that I setup url rewriting on was a Server 2008 box running ColdFusion 9, IIS 7.5 and Mango Blog version 1.6. I pretty much followed Adam's directions exactly, which started with installing Ionic's ISAPI Rewrite Filter. I ran into a few stumbling blocks when following the instructions before I was able to get the filter working correctly. I only wanted to run the url rewriting on one particular site so I opted for a manual installation instead of using the msi installer. I also wanted to use a native 64-bit solution, so I went with the 220.127.116.11 version that was compiled for 64-bits systems. Following the install instructions from Ionic, I attempted to place the IIRF.dll file in the /System32/inetsrv/IIRF/ directory. Setting up the permissions according to the document was not allowing the rewriting to properly load, so I eventually setup the files outside of the Windows directory all together which resolved my issues. That was definitely the most frustrating part of setting up the rewriting for my site. You can use the following link to display a status report, http://localhost/iirfStatus, which will allow you to verify if the filter loaded properly or not.
Once the filter is properly loading you need to add the following rules to your IIRF.ini file. These are taken directly from Adam's blog.
- #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 setting up the rewrite rules you still need to configure Mango Blog to use the new search engine safe urls. Starting in version 1.6 of Mango Blog, these settings have been moved from the config.cfm to the settings table in the database. Look for the system/url values and you will see where you can change the values so that the templates no longer contain the .cfm extensions. In order for me to edit the settings table in the MySql Query Browser I had to add a primary key field to the the table.
The other server I setup was running on Railo 3.1 and Apache 2.2. I had to enable the rewrite module in the http.conf file and then I placed my rewrite rules into my .htaccess file for each of the sites I wanted to apply rewrite rules. These are the rules that I ended up using.
- RewriteEngine on
- RewriteBase /
- RewriteRule ^index.cfm$ / [R=301,L,NC]
- RewriteRule ^archives.cfm/(.*)$ archives/$1 [R=301,NC]
- RewriteRule ^page.cfm/(.*)$ page/$1 [R=301,NC]
- RewriteRule ^post.cfm/(.*)$ recipe/$1 [R=301,NC]
- RewriteRule ^author.cfm/(.*)$ author/$1 [R=301,NC]
- # archives rule must be located before page rule for paging to work correctly
- RewriteRule archives/(.*)$ archives.cfm/$1 [PT,L,NC]
- RewriteRule page/(.*)$ page.cfm/$1 [PT,L,NC]
- RewriteRule recipe/(.*)$ post.cfm/$1 [PT,L,NC]
- RewriteRule author/(.*)$ author.cfm/$1 [PT,L,NC]
I've been unable to get the first set of rules to actually change the url in my browser as it appears the the second rules are immediately overriding the rewrite. This is different behavior than I experienced with the rewriting on IIS with the Ionic Rewrite Filter. I'm hoping to still figure this issue out as I would like the old url's to be permanently redirected to the new ses url's. Any ideas or tips on how to properly rewrite the old url's would be greatly welcomed.
The other thing to take note of is that I'm rewriting the post.cfm to recipe instead of post. You can make these changes to provide even easier to remember urls based on the content of your site.
I hope that this is helpful to anyone that is trying to setup url rewriting for Mango Blog.