Search code examples
coldfusioncoldfusion-9cfwheels

How do you acquire the rewritten CFWheels URL of an given page?


CFWheels has the URLFor() function for getting the internal URL based on supplied arguments. Is there a way to get the internal URL without supplying any arguments?

For example: Given a user navigates to "http://somedomain.com" or "http://somedomain.com/about/" or "http://somedomain.com/contact/" is there a method like ReWrittenURL() that returns something like "/" or "/about/" or "/contact/"?

Using URLFor() with no arguments returns "/home/index" or "/about/index" or "/contact/index".

CGI.SCRIPT_NAME returns "/rewrite.cfm"

Obviously with Javascript using document.location.href I can get what I'm after.


Solution

  • Does CGI.path_info have the value you're looking for?

    edit

    At first, I deleted this post, being utterly confounded. Now I've done a little test - I downloaded the latest wheels core files (1.1.6), extracted to an IIS 7.5 (with URL Rewrite module installed) + CF9 webserver, and edited the "web.config" file in the core root, setting "enabled='true'" for the rewrite rule. Also, since I was running this example from a subfolder, I changed the path from "/rewrite.cfm" to just "rewrite.cfm". This got me to the point where I was able to successfully requests urls like this:

    http://server/wheelstest/wheels/wheels

    From here, I edited the layout.cfm under views/wheels, adding:

    <cfdump var="#cgi#">
    

    When I then request the above URL (/wheelstest/wheels/wheels), I see the dump for the cgi scope. Under path_info, this is the value: /wheels/wheels.

    Next, I added a blank "index.cfm" file under views/wheels.

    When I request /wheelstest/wheels, I get this for path_info: "/wheels".

    When I request /wheelstest/wheels/, I get this for path_info: "/wheels/".

    When I request /wheelstest/wheels/index, I get this for path_info: "/wheels/index".

    When I request /wheelstest/wheels/index/, I get this for path_info: "/wheels/index/".

    So basically - cgi.path_info is doing for me exactly what you describe you want. What is different about your setup than mine, such that it isn't returning that value for you?