How to Strip/Remove the SiteID From the URL in Mura CMS

The first step in removing the SiteID from the URL in Mura CMS is to edit the file located at /config/settings.ini.cfm. Find the 'siteidinurls' attribute and set it to read siteidinurls=0. If you don't see this attribute, you might be using an older version of Mura, and you should probably upgrade your install. If for some reason, you cannot upgrade your install, then read this Mura blog posting titled Removing the SiteID from URLs in Mura.

Once this is done, you're usually pretty good to go. However, you can still actually navigate to your pages with the SiteID in the URL. In fact, when you preview your site from the Admin area, it usually includes the SiteID and someone expressed a desire to "fix" this for search engine optimzation (SEO), analytics, etc.

This is actually pretty easy to do by adding a few lines of code to your Mura CMS templates. The easiest thing to do would be to probably just add this to your 'html_head.cfm' file if you use it.


<cfscript>
    hasSiteIDinURL = false;
    if ( not application.configBean.getSiteIDinURLs() ) {
        urlstr = getPageContext().getRequest().getRequestURL();
        idx = listFindNoCase(getPageContext().getRequest().getRequestURL(), event.getSite().getSiteID(), '/');
        if ( idx gt 0 ) {
            hasSiteIDinURL = true;
            urlstr = listDeleteAt(urlstr, idx, '/');
            if ( len(trim(cgi.query_string)) ) {
                urlstr = urlstr & '?' & cgi.query_string;
            };
        };
    };
</cfscript>
<cfif hasSiteIDinURL><cflocation url="#urlstr#" addtoken="false" statuscode="301" /></cfif>

Hope this helps!

Comments

Isn't there now a switch in the admin that enables or disables the siteid. I seem to think this was a change in the 5.2 codebase.

Josen
# Posted By Josen Ruiseco | 3/17/10 1:08 PM
@Josen,

Sort of, the problem is, even if it's disabled, you can still navigate to pages with the siteid in the URL ... for example both www.domain.com/siteid/index.cfm AND www.domain.com/index.cfm will work.

Using the code snippet I provided in my post, if you navigate to www.domaing.com/siteid/index.cfm, it will automatically take you to www.domain.com/index.cfm and do so in a SEO fashion.
# Posted By Steve Withington | 3/17/10 1:31 PM
I should also point out to any readers who might employ this to be careful!

If your siteid is also a page's URL Title within your site, you could be in for some trouble. For example, if your siteid is 'default' and you have a page with a URL Title of 'default' you might want to change the URL title to something else.
# Posted By Steve Withington | 3/17/10 1:38 PM
I have updated mura to the most recent version, however i don't have any setting in my settings.ini.cfm file for "siteidinurls"

because of this, when i copy the code that you have provided into my header, i don't get a redirect
# Posted By Greg Moser | 3/22/10 11:56 AM
@Greg,
yeah, that's one of the issues i've asked Team Mura to work on ... getting newly added config settings added when an update is made. in the mean time, all you have to do is add 'siteidinurls=1' to your 'settings.ini.cfm' file.

let me know if you run into any other issues.
# Posted By Steve Withington | 3/22/10 12:14 PM
Awesome! thanks,

made that change and every thing works perfectly now.

thanks, again

-G
# Posted By Greg Moser | 3/22/10 12:22 PM

© 2024, Stephen J. Withington, Jr.  |  Hosted by Hostek.com

Creative Commons License   |   This work is licensed under a Creative Commons Attribution 3.0 Unported License.