Removing index.cfm From Mura CMS URLs on Windows/IIS7

If you have an installation of Mura CMS on Windows running IIS7+ and you're looking to remove "index.cfm" from the URL for search engine optimization (SEO) or any other reason, then here's a pretty simple and painless method to do just that.

First, IIS7 does not have their URL Rewrite Module installed by default. So you'll need to download and install URL Rewrite Module 2.0 for your server (x86 / x64).

After that's done, your next decision is to choose whether or not you wish to have the SiteID display in the URL. Some users prefer to have that, and some don't depending on their particular usage of Mura.

Option 1: Allow For Missing SiteID AND index.cfm From The URL

Create a "web.config" file with the following code and place it at the root of your Mura installation:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Mura CMS Rewrite Option 1" enabled="true">
                    <match url="^([a-zA-Z0-9/-]+)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{DOCUMENT_ROOT}{URL}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/index.cfm{URL}" />
                </rule>
            </rules>
        </rewrite>
        <defaultDocument>
            <files>
                <remove value="index.cfm" />
                <add value="index.cfm" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

Then, update your settings.ini.cfm file with the following settings and from the Admin > Reload Application:

siteidinurls=0
indexfileinurls=0

Option 2: Allow For Missing index.cfm From The URL, But Keep SiteID

Create a "web.config" file with the following code and place it at the root of your Mura installation:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Mura CMS Rewrite Option 2" enabled="true">
                    <match url="^([a-zA-Z0-9-]{1,})/([a-zA-Z0-9/-]+)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{DOCUMENT_ROOT}{URL}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/{R:1}/index.cfm/{R:2}" />
                </rule>
            </rules>
        </rewrite>
        <defaultDocument>
            <files>
                <remove value="index.cfm" />
                <add value="index.cfm" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

Then, update your settings.ini.cfm file with the following settings and from the Admin > Reload Application:

siteidinurls=1
indexfileinurls=0

Your site should now be able to handle URLs that are missing index.cfm.

Cheers!

How to Force Mura CMS to Use Primary Domains in SEO-Friendly Way

Mura CMS allows you to have multiple URLs assigned to each particular site. For example, you could have http://domain.com be your 'primary' domain and http://www.domain.com and http://www.anotherdomain.com set up as 'domain aliases' so that when you navigate to any one of these domains, Mura will serve up the desired site. This is pretty cool actually and there are a number of use cases out there on why you would want that to happen. However, if you want the 'primary' domain to be the one and only one used for SEO purposes and such, then you'll need to make just a couple of minor tweaks to make that happen. The best part is, I'll show you just how easy this is!

The first thing you'll need to do is copy the following method into your local contentRenderer.cfc. It's located at /{siteid}/includes/contentRenderer.cfc (or if you want this to be 'theme-specific' then edit the one located at /{siteid}/includes/themes/{themeName}/contentRenderer.cfc).

<cffunction name="doEnforceDomain" access="public" output="false" returntype="any" hint="By default, I will redirect users in an SEO-friendly way to your primary domain ... you may optionally override this by giving me an alternate 'primary' domain to enforce.">
    <cfargument name="domain" required="false" default="#$.siteConfig('domain')#" />
    <cfscript>
        var local = StructNew();
        local.doRedirect = false;
        local.servername = getPageContext().getRequest().getServerName();
        if ( local.servername neq arguments.domain ) {
            local.doRedirect = true;
            local.servername = arguments.domain;
            local.baseurl = getPageContext().getRequest().getScheme() & '://' & local.servername;
            // if not using a standard port, we should prolly include it
            local.port = getPageContext().getRequest().getServerPort();
            if ( local.port neq '80' and local.port neq '443' ) {
                local.baseurl = local.baseurl & ':' & local.port;
            };
            // uri returns '/index.cfm/path/to/page/'
            local.uri = getPageContext().getRequest().getRequestURI();
            local.urlstr = local.baseurl & local.uri;
            // append query string, if any
            if ( len(trim(getPageContext().getRequest().getQueryString())) ) {
                local.urlstr = local.urlstr & '?' & getPageContext().getRequest().getQueryString();
            };
        };
    
</cfscript>        
    <cfif local.doRedirect>
        <cflocation url="#local.urlstr#" addtoken="false" statuscode="301" />
        <cfelse>
        <cfreturn />
    </cfif>
</cffunction>

The last thing you'll need is an itsy-bitsy, teeny-weeny line of code that can actually be dropped in a number of different places. More on that in a second. However, if you want your entire site to always use the primary domain, then drop the following line of code into your local eventHandler.cfc in the onRenderStart() method. This is located in the same locations as the contentRenderer.cfc.

<cffunction name="onRenderStart">
    <cfargument name="$" />
    <cfset $.getContentRenderer().doEnforceDomain() />
</cffunction>

Remember how I mentioned you could drop this in a number of different places? Well, let me explain. Let's say you have an area of the site that uses a particular template and you want ONLY that area of the site to use a specific domain...for example 'http://docs.domain.com' for a documents area. Well instead of using the eventHandler.cfc route, you could just drop this at the top of the template and then anytime someone visits this area, they'll get re-routed properly and in a SEO-friendly manner. Isn't that sweet?

<cfscript>
    $.getContentRenderer().doEnforceDomain('docs.domain.com');
</cfscript>

As always, I hope this helps!

Cheers!

Removing index.cfm From Mura CMS URLs on Windows/IIS

While it's fairly easy to find out how to remove 'index.cfm' from your URL if you are using Apache (see Jamie Krug's blog and Matt Woodward's too), I haven't found any information on how to go about doing it if you're using Windows with IIS. As with anything else in this world, there are definitely more ways than one to accomplish this. However, I hope to show you an extremely painless and easy way to set this up.

Since everyone has different configurations, I'll point out here that this should work with IIS6+.

Step 1

Purchase and install ISAPI/rewrite/3 from Helicon Tech. As of the date and time of the writing of this article, it's only $99 per server and includes a free 45-day trial period. I do NOT recommend the freeware ISAPI_Rewrite Lite version since it does not allow for distributed .htaccess configurations, directory or web site level configurations. Other Lite version limitations can be found here.

Step 2

Now we need to create and add a .htaccess file to the root of our site with the appropriate rewrite rules. However, you need to determine whether or not you want to include the 'SiteID' in the URL.

In Mura CMS, you have the option to either include the 'SiteID' in the URL (which is the default behavior) or exclude the 'SiteID' from the URL. You can alter this behavior by simply editing the settings.ini.cfm file located under the 'config' directory.

For example, locate the siteidinurls and if you haven't changed it, it's probably set to siteidinurls=1. Assuming yours is set this way, your URL would would be rendered like http://www.mydomain.com/siteid/index.cfm/path/to/page/. If you change that to siteidinurls=0, then your URL would be rendered as http://www.mydomain.com/index.cfm/path/to/page/.

So depending on whether or not you want the SiteID to appear in your URL, you'll want to use either Option A or Option B below.

Option A — Remove SiteID AND index.cfm

Update your settings.ini.cfm file with the following settings:

siteidinurls=0
indexfileinurls=0

Then, drop the following code into your .htaccess file

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^([a-zA-Z0-9/-]+)$ /index.cfm%{REQUEST_URI} [PT]

Option B — Keep SiteID but Remove index.cfm

Update your settings.ini.cfm file with the following settings:

siteidinurls=1
indexfileinurls=0

Then, drop the following code into your .htaccess file:

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^([a-zA-Z0-9-]{1,})/([a-zA-Z0-9/-]+)$ /$1/index.cfm/$2 [PT]

That should be it. Hope that helps our friendly Windows IIS + Mura CMS users out there.

Peace.

More Entries

© 2017, Stephen J. Withington, Jr.  |  BlogCFC was created by Raymond Camden – Version 5.9.004

Creative Commons License  |  This work is licensed under a Creative Commons Attribution 3.0 Unported License.  |  Hosted by Hostek.com