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!

Comments
This is really awesome Steve, and something that I have been wishing that the BR guys would roll into Mura's base code.
# Posted By Dave Long | 4/26/11 11:15 AM
@Dave,

Well, considering I''m one of those 'Blue River' guys...I guess I should get on the ball then, eh?

I'll see if there's a clean way to implement something like this into the core. Maybe make the method available, and even have a radio option in the Site Settings for each site or something. Hmm.

Cheers!
# Posted By Steve Withington | 4/26/11 9:04 PM
Thanks Steve. Very useful.
# Posted By Jeff | 6/23/11 9:34 AM
Steve, thanks for this great piece of code.
I made one modification because the site I am using it on does not use "index.cfm" in the URLs.

I added:
<cfset local.urlstr = replacenocase(local.urlstr,"/index.cfm","")>

right after <cfif local.doRedirect> in the contentRenderer.cfc

that keeps it from adding in the "index.cfm" in the 301 redirect
# Posted By Jeff Pierson | 1/10/12 7:43 PM
SEO considers how search engines function, the PC modified calculations which direct search engine behavior, what people look for, the genuine inquiry terms or keywords typed into search engines.
# Posted By Write my Assignment Now | 1/22/18 5:24 AM
I think there are numerous other individuals who are occupied with them simply like me! To what extent does it take to finish this post, I trust you keep on having such quality articles to share!
# Posted By Assignment Writing Help UK | 2/20/18 5:10 AM
I endless like these sorts of posts which are made out of key encased work with the target that everybody can welcome it, a dedication of gratefulness is all around to post such an astounding idea. I'll be viewing the chance to be tied up with your assistance and I believe you post again soon.
# Posted By Essay Writing | 2/20/18 7:29 AM
Thanks for sharing this fact. I simply loved the way you defined the subject. It has correct information and also it's miles very interesting to examine. you have got maintained an amazing fine in an attractive manner. preserve sharing.
# Posted By Online Essay Company | 2/26/18 6:27 AM
Howdy! This post couldn't be written any higher! analyzing this publish reminds me of my preceding roommate! He continually stored speak me about this. I can ahead of this write-up to him. pretty positive he could have a great examine. Many thank you for sharing!
# Posted By Do My College Essay For Me | 2/26/18 6:34 AM
I'm sincerely inspired by this nicely-written and well-defined article on martial law. I was looking for data concerning a few records martial within the west due to the fact I've to finish my assignment in this subject matter.
# Posted By Pay for Essays in Australia | 2/26/18 6:36 AM
The data and the detail had been beginning past due difficult. I feel that your attitude is focal, its starting overdue well completely considered and simply strengthening to see some character who knows how to put those examinations down so nicely. tough to miss address this.
# Posted By Homework Tutor | 3/1/18 12:50 PM
It’s very excellent information and more real facts to provided that post.Thank you for sharing this information.
# Posted By SY0-501 braindumps | 5/8/18 5:12 AM
The Leading Assignment Help UK Firm Offers State Of The Art Services To Its Clients With A Promise Of Delivering All The Required Work Well Within The Deadline.
# Posted By Online Economics Project Help | 6/28/18 4:04 AM
Great Info! I Recently Came Across Your Blog And Have Been Reading Along. I Thought I Would Leave My First Comment. I Don’t Know What To Say Except That I Have
# Posted By Online Marketing Homework Help | 6/28/18 7:39 AM
The Arabic numerals have http://www.rolexsreplicas.org.uk rounded lines and blend with the overall http://www.replicawatches0.co.uk temperament. Elegant and unique, it is very eye-catching. A 3-point calendar display http://www.replicaonlineuk.org.uk window at 3 o'clock adds http://www.bestukwatches.co.uk practical functionality to the disc.
# Posted By replica watches uk | 7/23/18 2:08 AM
nice post thanks
# Posted By plombier neuilly sur seine | 9/17/18 7:06 PM
Such A Nice Post, Keep Providing Good Resources.
# Posted By Managerial Accounting Homework Help | 10/16/18 1:12 AM
My Friend Recommended This Blog And He Was Totally Right Keep Up The Fantastic Work!
# Posted By Take My Mechanical Project | 10/16/18 5:58 AM
nice post thanks very much
# Posted By choisir un bon chirurgien esthétique en tunisie | 10/18/18 10:12 AM
Cool post! By the way, if you need a professional help with writing essays or others kinds of papers we are ready to help you!
# Posted By Essays Masters | 10/20/18 12:55 PM
great information thanks :) :)
# Posted By docteur-nizar-mahjoub.com | 10/23/18 6:04 AM
nice post thanks very much :) :)
# Posted By chirurgie esthetique tunisie | 11/7/18 11:02 AM
Programming Assignment Help is efficient in reducing stress from your academic life. It can save most of your time. Hence you can utilize your time in other necessary works. However, it is essential to choose a proper service; else it can trouble you badly. To avoid this, you must check the online reviews for a better Computer Science assignment.
# Posted By programming assignment help | 11/26/18 5:40 AM
you can go through Allassignmenthelp.com reviews. It will help you to know about the services, and it will help you to know whether that site is reliable or not. This is a way of understanding the opinion of users, and it helps the website to maintain its functionality and reliability.
# Posted By AllAssignmentHelp reviews | 11/27/18 6:09 AM
You should study in a way that you do not compromise with your health. Good health is a prerequisite for you to be able to study efficiently and to maintain motivation to do so. Sometimes, assignments also act as a hindrance in following your timetable. In such situations, you can take assignment help.
# Posted By Assignment Help | 11/27/18 6:09 AM
Get online assignment writing service from top academic assistance provider company My Assignment Help OZ. We provide you authentic assignment service according to university requirement.
# Posted By online assignment help | 12/13/18 7:48 AM
Facing Sims 3 - Error Code 12, 16, 13 , 12 & 15 errors when saving the game on your Windows PC, follow this step by step guide to fix won't ...
# Posted By fix here | 12/24/18 6:30 AM
great info thanks
# Posted By avocat divorce | 1/23/19 5:12 AM
It is easy to understand, detailed and meticulous! I have had a lot of harvest after watching this article from you! I feel it interesting, your post gave me a new perspective! I have read many other articles about the same topic, but your article convinced me! I hope you continue to have high quality articles like this to share with veryone! http://papasgamesonline.com/papas-cupcakeria.html
# Posted By MangaFox | 3/7/19 3:29 AM
Buy online homework helper for write best homework. We provide homework helper service in Australia. Our experts easily do your homework. Experts write high-quality work. Our writers hold master and Ph.D. degrees from the top universities across the globe.
https://www.australiaassignmenthelp.com/homework-h...
# Posted By Australia Assignment help | 4/2/19 5:23 AM
great one
# Posted By Dr Malek | 4/30/19 10:11 AM
Original work guaranteed without a single sign of plagiarism https://ozwritingessay.com
# Posted By gerda stern | 5/6/19 7:32 AM
aking a loan online is dangerous when you don’t know anything about the company. Remember: if you take https://zz-cash.com microcredit online, your risks increase.
# Posted By loans online | 5/6/19 7:45 AM
Academic requirements can levy a tremendous amount of strain and pressure on the mental well-being of students. No matter how hard they try to divest themselves of these overbearing stresses, they always fall victim to them. A big reason for this is the way educational setups and curriculums have been devised. But, we have good news for you! There is no longer a reason for you to break under pressure, simply trust Done Essays https://www.doneessays.co.uk to come to your assistance. With our one-of-a-kind write my essay service, you can have all your writing-related issues resolved within a jiffy!
# Posted By Susanne McGuire | 5/9/19 2:15 AM
hello!,I really like your writing very much! proportion we keep up a correspondence extra approximately your article on AOL? I need an expert on this house to solve my problem. Maybe that's you! Having a look ahead to see you.
# Posted By advertising rates in singapore | 5/21/19 2:04 AM

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