Skip to main content
June 11, 2009
Question

Checking the CURRENT url in ColdFusion

  • June 11, 2009
  • 3 replies
  • 4770 views

Hi,

I'm trying to program some logic into my application that will check the URL, and if under certain conditions, will redirect appropriately.

For example, sometimes Search engines see the following all as the same thing:

http://www.mydomain.com

http://www.mydomain.com/index.cfm

http://mydomain.com

http://mydomain.com/index.cfm

What I need to do is ONLY use http://www.mydomain.com. If it's any of the others then I would like to redirect to the correct version using a CFHEADER.

Now...I know this can be done with something like .htaccess, but in this case, I need a CF only version.

If I look at something like #cgi.script_name#, I still cannot determine whether the URL ends in /index.cfm since all URL's above use the actual template, and CF isn't looking at the URL in the address bar, but the actual template being used right then and there.

As for the www's...I haven't a clue if it's even possible.

Many thanks for your help,

Mikey.

    This topic has been closed for replies.

    3 replies

    June 12, 2009

    In CF8 there is GetHttpRequestData() - that returns the full http request - I've not tested it but it may have more data you could use to discriminate your requests?

    Participating Frequently
    June 12, 2009
    
    
    
    ]]>

    StatusCode was added in CF8 so if you're on CF7 you'll need to use 2

    cfheader tags (one with statusCode 301 and statusText Moved

    Permanently for example and another one for the Location header).

    Mack

    ilssac
    Inspiring
    June 11, 2009

    I'm not sure what ColdFusion can do for you, since it is not the web server, or at least I hope it is not in a production enviornment.

    This is really a web server task, or better yet -- if you are concerned about Search Engines, a domain name server task.