EasyCFM.COM Forum / Coding Help! / CF8 SE Friendly URL's

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: CF8 SE Friendly URL's

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

donboe
07-25-2010 @ 4:13 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 383
Joined: Nov 2004

I used this tutorial in order to create  SE Friendly Url's

My menu is in a shared directory since It will grow over time and is included in all pages using <cfmodule

I have added this code:


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


to my Application.cfm, as explained in the tutorial but It isn't working. What am I doing wrong or is it because of my menu beeing in a different directory. This is the link structure for one of the menu items:


          <ul class="sub">
        <cfoutput query="getTypes">
               <li><a href="properties.cfm?type=#property_type_id#">#property_type_name#</a></li>
          </cfoutput>
          </ul>


“Good artists copy, great artists steal.” (Papblo Picasso)

Webmaster
07-26-2010 @ 11:42 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4421
Joined: Jan 2002

the code doesnt do the url replacing for you; it just interprets it.

<li><a href="properties.cfm?type=#property_type_id#">#property_type_name#</a></li>


needs to be:

<li><a href="/properties.cfm/type/#property_type_id#">#property_type_name#</a></li>


Notice that I put a "/" at the beginning (so you need to make them all virtual from the root) and also changed it to be /type/#var#.

Give that a try and let me know.

Pablo

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

\m/ (>.<) \m/
--- rock on ---

donboe
07-30-2010 @ 9:26 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 383
Joined: Nov 2004

Thank you Pablo, works great

“Good artists copy, great artists steal.” (Papblo Picasso)

shannanrohde
08-02-2010 @ 7:40 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 62
Joined: Sep 2006

Does this also work for Coldfusion mx7?

"You control the Internet, It doesn't control you" - http://www.uniquemadness.com

Webmaster
08-02-2010 @ 4:31 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4421
Joined: Jan 2002

Been a while since I used CF7, but I think it began
working on 7 and higher.

Also, one thing I generally change in that code is
this:


<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;
                     }
            }
      }
  // set the value to the url scope
  url[var_name] = value_to_set;
  var_name = "";
  }
}
}
</cfscript>

That (see bold above) will make the variables be stored
in the URL scope; isntead of the variables scope. Makes
it easier to handle for me... but a matter of choice.

Glad you got it to work!

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

\m/ (>.<) \m/
--- rock on ---




Copyright © 2002 - 2009. EasyCFM.COM, LLC.
Powered by < CF FORUM > v.2.0
 
Download the EasyCFM.COM Browser Toolbar!