Fancy URL parsing and variables

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Fancy URL parsing and variables

    I would like to create a site with some easy-to-remember URLs, e.g.
    [url]www.mysite.com/about[/url] or [url]www.mysite.com/archives/2005/6/This_is_a_page_title[/url]. Is
    there a way to have ColdFusion parse URLs such as these into variables and
    values? I am hoping to avoid messy URLs such as
    [url]www.mysite.com/archives.cfm?year=2005&month=6&title=This_is_a_pag e_title[/url].

    Hopefully this makes sense. I'm aware that some blogging tools do similar
    things already, but I think I've only seen this technique work in PHP. I hope
    it can be done in ColdFusion as well.

    Thanks,
    Chris

    martian_iii Guest

  2. Similar Questions and Discussions

    1. Parsing a url for variables
      Suppose I have a url string such as: http://123.com/index.php?value1=This,valueB=that,value7=9 Within index.php of course, I can use $value1,...
    2. [PHP] URL variables parsing error?
      Hi, hiaer@azrael.sk wrote: Try this: <?php echo "var1: {$_GET}"; echo "var2: {$_GET}";
    3. URL variables parsing error?
      Hi all, I use RedHat9.0 with Apache 2.0.40 & PHP 4.2.2 and I have problem with parsing URL variables... I use this URL:...
    4. Parsing Variables
      I would like to create a script that reads a file name that follows a specific format and have it parsed into 2 variables. The format is as...
    5. Parsing POST and GET variables simultaneously?
      Isn't it possible to get variables from POST and GET simultaneously? Consider the script test.rbx below: require 'cgi' cgi = CGI.new print...
  3. #2

    Default Re: Fancy URL parsing and variables

    Sure. I use that technique myself in a couple of different ways.

    For example, this code will give you just the filename of a particular url:

    <cfset request.TheNameOnly=ListFirst(ListLast(cgi.Script_ Name,"/"),".")>

    So if the url was [url]http://foohbar.com/thisismypage.cfm[/url] the code above would
    return the value "thisismypage".

    Now lets say you have a CMS with the web page data being stored in a database.
    One of the fields is indexed and named "tableName.friendlyName". You would
    then do a sql query:

    select * from tableName where tableName.FriendlyName='thisismypage'

    Poof. Instant friendly url system for a dynamic web site.

    Of course I am significantly oversimplifying the picture here (i.e. use
    cfqueryparam always; do dupe checks before allowing data into the friendlyName
    field) but it should be enough to give you the idea.

    If you wanted something 'less firendly' you could use the same parsing code
    above, and then find the underscore character and strip out everything to the
    left of it. This would make a page named 'page_123.cfm' yield a value of
    '123', which would correspond to your primary key in your database. Years ago
    I wrote a kinda zany article for CFDJ that illustrated that technique coupled
    to some stuff that many people thought was nuts but was then and is now the
    only way to solve certain problems on shared hosting.

    Hope this helps,

    --Matt--
    MSB Web Systems... [url]http://mysecretbase.com[/url]
    I"Using words to describe magic is like using a screwdriver to cut roast
    beef."
    - Tom Robbins


    MattRobertson Guest

  4. #3

    Default Re: Fancy URL parsing and variables

    Matt,

    Thanks for the advice.

    I think your suggestion of publishing dummy pages that execute a bit of dynamic code is probably the best way to go. Thanks again.

    Chris
    martian_iii Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139