-1

I need to get the current url, like https://www.mypage.com/subfolder/iamhere.html

I know that I can get the templatePath using getCurrentTemplatePath(), but I need the url and I don't know how to do that.

I searched in google and stackoverflow, but I always ended up either with non cfml code or the templatePath.

Userx10xC
  • 124
  • 9
  • If you have debugging turned on, look at your cgi variables. – Dan Bracuk Mar 17 '23 at 11:56
  • 1
    Use the CGI scope – haxtbh Mar 17 '23 at 12:51
  • 1
    https://stackoverflow.com/questions/45137347/how-to-get-current-page-url-in-coldfusion-i-am-getting-home-page-url-index-cfm – Adrian J. Moreno Mar 17 '23 at 13:54
  • Does this answer your question? [How to get current page URL in coldfusion ? I am getting home\_page\_URL/index.cfm while fetching current page URL](https://stackoverflow.com/questions/45137347/how-to-get-current-page-url-in-coldfusion-i-am-getting-home-page-url-index-cfm) – James A Mohler Mar 17 '23 at 15:52

2 Answers2

2

The sample URL you give is an HTML page. For that, you'd need Javascript. Something like:

var addr = window.location.href;

For ColdFusion, be sure you're using code on an actual CFML page. For instance: https://www.mypage.com/subfolder/iamhere.cfm

If this is the case, like others have said, you should use the CGI scope. As an example:

<cfset addr = (cgi.SERVER_PORT IS 443?'https':'http') & "://" & cgi.HTTP_HOST & cgi.HTTP_URL>
CFMLBread
  • 734
  • 3
  • 7
0

All of the pieces are available in the CGI scope. dump(CGI)

Daemach
  • 417
  • 5
  • 13