Search code examples
coldfusionapplication.cfcfusebox

How do I create Search Engine Safe URLs in Fusebox 5.1 noxml?


How do I create Search Engine Safe URLs in Fusebox 5.1 noxml?

For instance, I want this: http://www.site.com/index.cfm/app.welcome/

Instead of this: http://www.site.com/index.cfm?fuseaction=app.welcome

Fusebox 5.1 is suppose to be able to do this. I've read this article, but it only applies to the xml version. I know so little, I am not sure where to start. How do I do it with the noxml version of fusebox?

Update: It looks like I need to add this to my Application.cfc file. Still not working though...

FUSEBOX_PARAMETERS.myself = "index.cfm/fuseaction/";
FUSEBOX_PARAMETERS.queryStringStart = "/";
FUSEBOX_PARAMETERS.queryStringSeparator = "/";
FUSEBOX_PARAMETERS.queryStringEqual = "/";

Solution

  • Fusebox 5.1 allows you to use SES URLs by allowing you to change ? & to /. You still need to provide your own rewriter. However, if you are able to upgrade to 5.5 it supposedly handles rewriting, too.

    Example Rewriter

    http://www.fusebox.org/forums/messageview.cfm?catid=31&threadid=6117&STARTPAGE=2

    <cfscript>
    // SES converter
    qrystring = ArrayNew(1);
    if ( Find("/",cgi.path_info) eq 1 and Find("/#self#",cgi.path_info) eq 0 ) {
    qrystring = cgi.path_info;
    } else if ( Len(Replace(cgi.path_info,"#self#/","")) gt 0 ) {
    qrystring = ListRest(Replace(cgi.path_info,"#self#/","#self#|"),"|");
    } else if ( FindNoCase("#self#/",cgi.script_name) gt 0 ) {
    qrystring = ListRest(Replace(cgi.script_name,"#self#/","#self#|"),"|");
    }
    arQrystring = ListToArray(cgi.path_info,'/');
    for ( q = 1 ; q lte ArrayLen(arQrystring) ; q = q + 2 ) {
    if ( q lte ArrayLen(arQrystring) - 1 and not ( arQrystring[ Q ] is myFusebox.getApplication().fuseactionVariable and arQrystring[ q+1] is self ) ) {
    attributes['#arQrystring[ Q ]#'] = arQrystring[ q+1];
    }
    }
    </cfscript>
    

    If you choose to use Coldcourse...

    http://coldcourse.riaforge.com

    Below will help you get started. You can ignore server-side rewriting (ISAPI for IIS) if you want /index.cfm/circuit/action/ formatted URLs. But if you want /circuit/action/ or /blah/ you'll need to make it server side.

    application.cfc

    Put on onApplicationStart (or onRequestStart for testing) to put in memory.

    <cfset application.coldcourse = createObject("component","components.util.coldcourse").init("/config/coldcourse.config.cfm")>
    

    index.cfm Place this before the framework loads

    <cfset application.coldcourse.dispatch(cgi.path_info, cgi.script_name) />
    

    coldcourse.config.cfm (example config)

    <cfset setEnabled(true)>
    <cfset setFrameworkEvent("action")>
    <cfset setFrameworkSeparator(".")>
    <cfset setFrameworkActionDefault("")>
    <cfset setUniqueURLs(true)>
    <cfset setBaseURL("http://www.mysite.com/index.cfm")>
    
    <!--- CUSTOM COURSES GO HERE (they will be checked in order) --->
    <!--- for http://www.mysite.com/about/ pages --->
    <cfset addCourse("components")>
    <cfset addCourse(pattern="about",controller="main",action="about")>
    <cfset addCourse(pattern="contact",controller="main",action="contact")>
    <cfset addCourse(pattern="help",controller="main",action="help")>
    
    <!--- If nothing else matches, fall back to the standard courses (you probably shouldn't edit these) --->
    <cfset addCourse(":controller/:action/:id")>
    <cfset addCourse(":controller/:action")>
    <cfset addCourse(":controller")>
    

    Install ISAPI Rewrite

    Make sure you are using the correct rewrite regex because version 2.0 is different from 3.0.

    Example for 2.0 script:

    # Coldcourse URL Rewrite for CF
    IterationLimit 0
    RewriteRule ^(/.+/.+/.*\?.+\..*)$ /index.cfm/$1
    RewriteRule ^(/[^.]*)$ /index.cfm/$1
    

    Disable Check if File Exists on web server

    Do this for IIS if you're getting a 404 error in your web logs.

    1. Open the IIS manager
    2. Right click on a site and choose Properties
    3. Click the Home Directory tab
    4. Click the Configuration button (lower right of dialog)
    5. Click the .cfm extension and choose 'Edit'
    6. The lower left checkbox: "Check that File Exists"