Friday, October 22, 2010

Retrieving the Original URL in ColdFusion when doing URL Rewrites (IIS7 and Apache 2)

As I have stated before, I have begun to play with PHP and there is a server variable which I love that I was trying to get similar in ColdFusion and that is the following variable:

Basically that variable outputs the original URL before the rewrite. So if I requested the following URL:

http://mysite/this-is-a-test/something.html

Which rewrote to
http://mysite/index.cfm?{my query string that I build}

It would output /this-is-a-test/something.html

Which I thought it was fantastic! Now in ColdFusion, doing a simple CGI dump you do not get any variable with that value, but the servers have little secrets which I would like to share.

If you are using IIS7 you can use either:

  • HTTP_X_ORIGINAL_URL
    this server variable contains the original URL in decoded format;
  • UNENCODED_URL
    this server variable contains the original URL exactly as it was requested by a Web client, with all original encoding preserved.

Click here to read more @ IIS 7 Docs

Both of this can be accessed thru the cgi scope, even though they do not appear when you do a dump.

If you are using Apache 2 (which is what I have on my mac) you can use:

  • REDIRECT_URL

Click here to read more @ Apache 2 Docs

No comments:

Post a Comment