Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Checking the CURRENT url in ColdFusion

Engaged ,
Jun 11, 2009 Jun 11, 2009

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.

4.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 11, 2009 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 12, 2009 Jun 12, 2009
<cfif CGI.HTTP_HOST neq "www.mydomain.com">
<cflocation url="http://www.mydomain.com" statusCode="301">
</cfif>

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 12, 2009 Jun 12, 2009
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources