Solved

Search Engine Friendly Pages Sub '?' for '/'

Posted on 2003-11-08
8
230 Views
Last Modified: 2013-12-24
Lets say we have a profile page with the following URL

http://www.mypage.net/profiles/test.cfm?contact_ID=71

How would we make the URL without the '.cfm' ... into something like this

http://www.mypage.net/profiles/test/contactID/71

All the sample code I have seen still had the '.cfm' still in the URL. I would like to be able to hide the fact that the page is being generated with cold fusion.
0
Comment
Question by:TallGuyMD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Expert Comment

by:dc197
ID: 9708502
You would rename the file from "test.cfm" to "index.cfm".

Make sure that your webserver is set up to treat files called "index.cfm" as the default file.

If you make a directory called "test" and put your original file in there but renamed index.cfm,
http://www.mypage.net/profiles/test.cfm
then becomes
http://www.mypage.net/profiles/test/



You cannot swap the ? and the = for / because CFM will not know that they are form/url variables and will treat them as part of the path.
0
 

Author Comment

by:TallGuyMD
ID: 9709043
Actually, you should be able to rename the page as an index page, then follow the directions below...


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.

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.
0
 

Author Comment

by:TallGuyMD
ID: 9709048
I guess you could define a variable to tell the script when to start collecting the variables

Example))) <cfscript>
   debug = 0;
   valid_extensions = "html,htm,cfm,asp,jsp";

But how would you remove remove the '.'
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 1

Expert Comment

by:kjuliff
ID: 9709799
I just tested the script and it is really good. But I'd like to hide the parameters all together. eg
http://www.mypage.com/mb3/viewmessages.cfm/Forum/1/Topic/5224/sortby/d
works BUT it the sE indexes this then there'd be so many pages (combinations of parameters) indexed...

I'd like to have
http://www.mypage.com/mb3/viewmessages.cfm only displayed as the URL. Or am I missing something?



0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11052445
PAQed, with points refunded (20)

modulo
Community Support Moderator
0
 

Expert Comment

by:finnstone
ID: 11193988
tallguy, your code does not do anything.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question