Mura: Creating Nice Friendly URL's and remove Site ID

UPDATE: Starting in Mura 5.2 you can now simply set your /config/settings.ini.cfm siteIDInURLs attribute to 0.


The good people who created Mura have already provided a number of ways to rewrite URL's but if you have never done this within Sava finding the correct information on their website can be tedious. Below is a step by step guide taken from various posts and the readme file within the Sava download.

These instructions work on Coldfusion 8 server, I have not tested it on anything else so I don't want to comment on the other methods. For more information download Sava or visit the Sava website

Adding the "go" FriendlyURLServlet to ColdFusion Server 8

1 - When you unzip your Sava download it contains a folder called libs. Within it is a jar file. You must add this jar file to your own libs folder in your Coldfusion directory normally drive:\ColdFusion8\wwwroot\WEB-INF\lib

2 - Next you will need to add a custom servlet mapping to your ColdFusion server web.xml file. The lib/web-xml.txt file in your Sava download has two snippets. One for "Jetty" and the other covers most servlet containers

Put only the one that is right for your setup inside your drive:\ColdFusion8\wwwroot\WEB-INF\web.xml file.

With JRun, all servlet tags need to be above all servlet-mapping tags. Place the code right above the first servlet-mapping tag so that no servlet mapping tag is above any servlet tag. For example....

view plain print about
1<servlet id="coldfusion_servlet_8799">
2 <servlet-name>JspLicenseServlet</servlet-name>
3 <display-name></display-name>
4 <servlet-class>coldfusion.bootstrap.BootstrapServlet</servlet-class>
5 <init-param id="InitParam_Z103401311065856789">
6 <param-name>servlet.class</param-name>
7 <param-value>coldfusion.license.JspLicenseServlet</param-value>
8 </init-param>
9 </servlet>
10
11
12<!--DEFAULT CUSTOM -->
13<servlet>
14<servlet-name>FUServlet</servlet-name>
15<display-name>FriendlyURLServlet</display-name>
16<description>Translates friendly URLs to objects</description>
17<servlet-class>com.blueriver.sava.FriendlyURLServlet</servlet-class>
18</servlet>
19
20<servlet-mapping>
21<servlet-name>FUServlet</servlet-name>
22<url-pattern>/go/*</url-pattern>
23</servlet-mapping>
24<!-- END DEFAULT CUSTOM -->
25
26 <servlet-mapping>
27 <servlet-name>JspLicenseServlet</servlet-name>
28 <url-pattern>*.jsp</url-pattern>
29 </servlet-mapping>

3 - In Mura[version number]\www\config\setting.ini.cfm set the stub attribute to "/go" make sure you put the forward slash / before the word go! ie. /go.

4 - Then restart the ColdFusion server so the new setting take affect.

Problems? Make sure you restart your CF server and in the CF administrator check out the "System Summary" to make sure that you see the com.blueriver.sava.jar

Removing the SiteID

Now that's done you should have friendly URL's however you will still have the SiteID in the URL, want to get rid of it?

The following assumes that you have all ready set up the FriendlyURLServlet above and set the settings.ini.cfm stub attribute to /go

To get URL's to render like /go/about-us/ follow these steps:

1 - Download the latest version of Sava, if your build is older than 5.0.503 then you can simply update/replace the following files...

MuraRoot/trunk/www/default/includes/contentRenderer.cfc

2 - Next uncomment the getUrlStem() method found in the contentRenderer.cfc file at the above location.

view plain print about
1<cffunction name="getURLStem" access="public" output="false" returntype="string">
2    <cfargument name="siteID">
3    <cfargument name="filename">
4    
5    <cfif arguments.filename neq '>
6        <cfif application.configBean.getStub() eq '
>

7            <cfreturn "/index.cfm" & "/" & arguments.filename & "/"/>
8        <cfelse>
9            <cfreturn application.configBean.getStub() & "/" & arguments.filename & "/" />
10        </cfif>
11    <cfelse>
12        <cfreturn "/" />
13    </cfif>
14
15</cffunction>

3 - Next edit the /MuraRoot/index.cfm and change it to say:

view plain print about
1<cfinclude template="tasks/content/contentServerRoot.cfm" >

4 - now edit the /MuraRoot/contentServer.cfm and change it to say:

view plain print about
1<cfinclude template="tasks/content/contentServerRootStub.cfm" >

5 - Last reload Mura this can be done via the Sava Administration panel or by appending "?appreload" to the end of your sites URL.

That's it! Sava have made it really simple, I just wanted to put it all on one page for my own reference and others.

Note: if your site is already established and your engine results still has the old ID's it will skill resolve to the same page. You don't need to remove URL's from Google or put redirects on. Google and other search engines will eventually catch-up. However if you have PageRank on a particular page it will help to use 301 redirects to make sure it gets transferred to the new page URL.

TweetBacks
Comments
Matt Darby's Gravatar Maybe I am missing something but doesn't SAVA allow for creating friendly urls out of the box without having to modify JRun's web servlet?
# Posted By Matt Darby | 16/02/09 15:41
Glyn Jackson's Gravatar they seem to provide a number of ways to do this, yes. but using the FriendlyURLServlet with the siteid removed the url structure is /go/filename where using the one out of the box it gives me /index.cfm/filename/.

Quote Sava readme:
"If your Web Server/Servlet Container does not support the extension of urls to include query parameters after index.cfm (i.e. gosava.com/sava/products/index.cfm/widgets), or you simply prefer to use the "go" servlet instead (i.e. gosava.com/go/sava/products/widgets/)"

so for me I just liked the URL better without index.cfm
# Posted By Glyn Jackson | 16/02/09 16:47
Matt Darby's Gravatar Gotcha, I agree about removing the site folder name from the URL. I have multiple sites that am currently developing on but I was hoping to find a solution that wouldn't involve the modifying of the web servlet when using a shared hosting environment.
# Posted By Matt Darby | 16/02/09 17:53
magnus's Gravatar I am trying to get the FriendlyURLServet to work with Railo, but the directory a little diferent and this has left me confused. There is no WEB-INF/lib folder. Instead the closest equivalent appears to be WEB-INF/railo/library.
The only instructions I have found refer to the CF8 situation. Any ideas on how it should be done for Railo?
# Posted By magnus | 23/02/09 20:42
 

About Me

Glyn Jackson, 28 years old, MD and senior developer of a development firm based in Staffordshire called Newebia Ltd. Academic background in BSc Information System & Internet Commerce. Online marketing expert (EE Ranked) and .NET developer. Has been developing with ColdFusion for 5 years and loves it. "I am not a veteran in ColdFusion but I do work on challenging projects which help me learn more about ColdFusion and if I can contribute to the community in anyway then, it's all good!"

Recommends

  • ColdFusion