How to Remove WWW from the URL in Mura CMS with ColdFusion

Recently, a Mura CMS user asked how to remove the 'www' from the URL. So I thought I would whip up a quick post on how to do it.

  1. Login to the Admin and go to your 'Site Settings' (top-right on yellow toolbar).
  2. Select the site you wish to enforce this rule on.
  3. On the 'Basic' tab, make sure you have 'yourdomain.com' in the 'Domain' field.
  4. Also, make sure you list 'www.yourdomain.com' in the 'Domain Alias List' text area.
  5. Click 'Update'
  6. Now we'll edit a file that would probably be included on each page in your site such as \{siteid}\includes\themes\merced\templates\inc\html_head.cfm
  7. Copy and paste the code below into the top of the file that is located on each page:


<cfscript>
    myDomain = "yourPreferredDomain.com";
    domainIsCorrect = true;
    if ( getPageContext().getRequest().getServerName() neq myDomain ) {
        domainIsCorrect = false;
        urlstr = "http://" & myDomain & getPageContext().getRequest().getRequestURI();
        if ( len(trim(getPageContext().getRequest().getQueryString())) ) {
            urlstr = urlstr & "
?" & getPageContext().getRequest().getQueryString();
        };
    };
</cfscript>
<cfif not domainIsCorrect><cflocation url="
#urlstr#" addtoken="false" statuscode="301" /></cfif>

That's it! Enjoy.

Comments
Thanks for sharing this helpful information. Before coming to your blog I was wondering that do URL with or without www different or effect performance of our website. But now it's clear for me. So I decided to remove www from URL and the above code really works.
# Posted By agnes james | 10/19/12 3:35 AM

© 2014, 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