Products

Products
Viewing By Entry / Main
April 7, 2007

ColdFusion SES URL

SES urls stands for search engine safe urls. Which means to replace those long funky url query_string with "/" delimited list of variables and values. This is supposed to increase your SEO, better search engine listing rank, and just look better. I for one don't think it increases your Goggle SEO, but as long as it's easy and it doesn't hurt, why not.

Instead of using this link:
mysite.com/index.cfm?var1=val1&var2=val2&var3=val3

You'll use this:
mysite.com/index.cfm/var1/val1/var2/val2/var3/val3

First, make sure you can do it the way I'm going to show you. A little test on your web site. If you fail this test then move on to something else because I can't help you, maybe.

Test:
Go to your site and put /var1/val1/var2/val2 at the end of a page url an try it out. What do you see? If the page shows a big fat error message, then you have a problem and I can't help you, bye bye. Oh wait.. Do you have access to the web.xml file of the server? That's in the WEB-INF directory. If your on a shared hosting, then probably not. But if so, add this or find it in that file and uncomment it (unsupported in Tomcat and SunONE servers):

<servlet-mapping id="macromedia_mapping_6">
<servlet-name>CfmServlet</servlet-name>
<url-pattern>*.cfml/*</url-pattern>
</servlet-mapping>
<servlet-mapping id="macromedia_mapping_7">
<servlet-name>CfmServlet</servlet-name>
<url-pattern>*.cfm/*</url-pattern>
</servlet-mapping>
<servlet-mapping id="macromedia_mapping_8">
<servlet-name>CFCServlet</servlet-name>
<url-pattern>*.cfc/*</url-pattern>
</servlet-mapping>

Moving on..

Once you get that part varified or working there's three simple things you must do to use SES urls.

First you must use SES url links. This means that when you create an "a href" link, to use /*/*/ instead of ?*=*&*=*. Get my drift? Duh.

Second, you must parse all that stuff back into url qury_string so your page can use them as normal. Even though you use /color/red/shape/square, your site needs to see and use url.color=red and url.shape=square. Here's the code and I would suggest you use it in your Application.cfc's request function:

<cfscript>
pathInfo = reReplaceNoCase(trim(cgi.path_info), '.+\.cfm/? *', '');
i = 1;
lastKey = "";
value = "";
if(len(pathInfo)){
   for(i=1; i lte listLen(pathInfo, "/"); i=i+1) {
    value = listGetAt(pathInfo, i, "/");
    if(i mod 2 is 0) url[lastKey] = value;
    else lastKey = value;
   }
   if((i-1) mod 2 is 1) url[lastKey] = "";
}
</cfscript>

And most importantly, unless you can find a better way to beat this, you now have to use fully qualified urls almost everywhere, this means to use your full domain path instead of relative links. Not in things like img tags or cfincludes, but mostly all href links. I have a pretty elegant way of using the application scope to paramaterize it site wide. Existing sites may need to do some find and replacing at href's.

Comments

This is great, it easily gave me this: www.domain.com/test.cfm/var1/test
url.var1 = test

great..

but the problem is it has "/test.cfm/" in the URL which is bad from SEO. How can you change that to simply "/text", final url: www.domain.com/test/var1/test
url.var1 = test

Any solutions would be great. thanks for all the work and code :)


The same issue has been happening for me. You can see the issue if you go to http://www.jasonpresley.net/demo/index2.cfm. That page loads just fine. However, if you go to http://www.jasonpresley.net/demo/index2.cfm/about-our-company then none of the css on the page loads. I am using mangoblog on my site and it uses SE friendly urls so I know it can be done on my server but I can get it to work for my own code. If anyone knows what is going on PLEASE let me know!!!



Copyright © 2005-2006 Clint Willard. All rights reserved.
Aura skin for Clint Willard's BlogCFC inspired by Brooks Bilson's Bolg.
All trademarks property of their owners.