Copy link to clipboard
Copied
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/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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
<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
Copy link to clipboard
Copied
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?