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
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.
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.
because of this, when i copy the code that you have provided into my header, i don't get a redirect
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.
made that change and every thing works perfectly now.
thanks, again
-G