SE Friendly URL's

Having search engine friendly sites these days is no longer a good idea...it's a MUST!

More and more SE's are ignoring the META tags we have all come to know and love and are concentrating more and more on the actual content of your page. But what happens if the page is called dynamically? Answer - The bot falls on its bot! Most SE bots will not follow a URL once it hits the ? or & which indicates the dynamic content and will grind to a halt. This tutorial will show you a method to make sure the SE bots really dig into your site and index every possible page!

The bones of the script below are very simple and lightning fast. In a nutshell the script interrogates the URL you pass it to determine where the URL ends and the dynamic content begins. Take this example:

http://www.yourdomain.com/page.cfm?Var1=2&Var2=2&Var3=3

If you rewrote the above to get rid of the ? and & and replace them all with / to make it look like folders you would get:

http://www.yourdomain.com/page.cfm/Var1/1/Var2/2/Var3/3

Marvellous!! We now have a URL that the SE bot will follow as it looks like a bunch of folders!

But how do we use this in our query? That?s where the script comes in. On the page where you are passing this new URL to i.e. page.cfm simply add the script BEFORE the queries and write your query as normal.

The script will basically scan through the URL looking for the extension, the .cfm in this case. Once it finds it, it then starts looking for another /. Now it knows that if it finds another one it?s a dynamic URL and it needs to start collecting the variables.

Obviously each variable name will have a value so it knows that after the very next / will be the value for the variable. It will then continue to decipher the rest of the URL until it runs out of /?s.

Your query will then accept those variables in the normal way and process.

Here?s the script:

<cfscript>
   debug = 0;
   valid_extensions = "html,htm,cfm,asp,jsp";
   url_suffix = ".html";
   path_to_parse = replacenocase(cgi.path_info, cgi.script_name, "");
   if (listlen(path_to_parse, "/") gte 2) {
      var_name = "";
      for (x = 1; x lte listlen(path_to_parse, "/"); x = x + 1) {
      if (var_name eq "") {
         var_name = trim(listgetat(path_to_parse, x, "/"));
         if (not refind("^[A-Za-z][A-Za-z0-9_]*$", var_name)) {
            var_name = "";
            x = x + 1;
         }
      }
      else {
           value_to_set = listgetat(path_to_parse, x, "/");
           if (trim(valid_extensions) neq "" and x eq listlen(path_to_parse, "/")) {
               for (ext = 1; ext lte listlen(valid_extensions); ext = ext + 1) {
                     extension = "." & listgetat(valid_extensions, ext);
                     if (right(value_to_set, len(extension)) eq extension) {
                          value_to_set = left(value_to_set, len(value_to_set) - len(extension));
                          url_suffix = extension;
                          break;
                     }
            }
      }
  setvariable(var_name, value_to_set);
  if (isdefined("debug") and debug) {
     writeoutput("<!-- " & var_name & " = " & value_to_set & " -->" & chr(10));
  }
  var_name = "";
  }
 }
}

</cfscript>

So where to use it? Well the easiest method is to use it as an include in each page that has your SE friendly URL passed to it. You could just add it to the Application.cfm file as well.

The down side is that SE bots can go a bit mental as happened to me last night! My normal page views are around 2-3k per day. Yesterday it shot up to 11.5K!! Why? Because the Inkotomi bot indexed every resource on the site (around 900) and all the associated pages!!

So there you go! SE bots will now trawl your site until they are full to the brim! For a working example, check out www.webmasteredge.com and just watch the URL?s as they are passed from page to page in the resources section.

Amendment: Some users have reported a bug with the above tutorial. If you copy and paste the script direct into your page you may find that the script will not work correctly and comes up with a compilation error.
If this happens, simply strip out the whitespace before each line of code in the script and this should fix it.

All ColdFusion Tutorials By Author: Phil Williams
  • SE Friendly URL's
    Get the search engines to really dig deep into your site by replacing the ? and & in your dynamic URL's with /. Tricks the SE bot into thinking it's a regular folder and eats up your content!
    Author: Phil Williams
    Views: 35,618
    Posted Date: Wednesday, February 12, 2003
  • Currency Conversion using Web Services
    A very simple currency convertor that uses the latest exchange rates through the available Web Service
    Author: Phil Williams
    Views: 24,913
    Posted Date: Wednesday, April 21, 2004
  • Remote Reboots with ColdFusion MX
    This tutorial will tell you how to reboot your server without even logging in.
    Author: Phil Williams
    Views: 15,424
    Posted Date: Sunday, July 18, 2004
  • Create and email ZIP files on the fly!
    This tutorial will allow you to zip up a file or files on your server and email them to you. The whole tutorial runs to less than 20 lines of code!
    Author: Phil Williams
    Views: 18,666
    Posted Date: Thursday, October 28, 2004
  • Stop automated form submission by using Image Verification
    This tutorial will show you how to stop automatred form submissions by generating a random image that must be verified before the form is submitted.
    Author: Phil Williams
    Views: 20,101
    Posted Date: Thursday, October 20, 2005
  • Complete site encryption!
    This tutorial will show you how to encrypt an entire site by recursively working though the folder structure encrypting all the cfm files and copying any non-cfm files whilst keeping the directory structure intact.
    Author: Phil Williams
    Views: 12,218
    Posted Date: Sunday, July 16, 2006
  • Simple and Efficient RecordSet Paging
    A simple and efficient method to page through hundred or even thousands of recordset result.
    Author: Phil Williams
    Views: 5,248
    Posted Date: Thursday, January 8, 2009
  • Backup Your MySQL Database with just ColdFusion Code

    This tutorial will show you how to quickly and easily backup and restore a MySQL database using just ColdFusion scripts and avoiding having to use CFEXECUTE which is normally disallowed on shared hosting platforms.

    ColdFusion 8 has some handy tags that will provide database detail but what if you're running CF7? Normally you would have to resort to running the mysqldump command but this is restrictive if you wanted to provide your users with a method to backup their databases.


    Author: Phil Williams
    Views: 2,954
    Posted Date: Friday, July 10, 2009
Download the EasyCFM.COM Browser Toolbar!