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.
- Login to the Admin and go to your 'Site Settings' (top-right on yellow toolbar).
- Select the site you wish to enforce this rule on.
- On the 'Basic' tab, make sure you have 'yourdomain.com' in the 'Domain' field.
- Also, make sure you list 'www.yourdomain.com' in the 'Domain Alias List' text area.
- Click 'Update'
- 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
- 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