Skip to main content
January 18, 2007
Answered

function for getting full current page url

  • January 18, 2007
  • 5 replies
  • 2632 views
Hello Everyone!
Is there a funtion to get your full current page url? With the http:// and possible url variables?
Thank you!
This topic has been closed for replies.
Correct answer BKBK
<cfoutput>#" http://" & CGI.HTTP_HOST & CGI.SCRIPT_NAME & IIf(len(trim(CGI.QUERY_STRING)),DE('?'),DE('')) & CGI.QUERY_STRING#</cfoutput>

5 replies

BKBK
Community Expert
Community Expert
January 27, 2007
> I have used the CGI variables to get the info you mentioned.
> However, it does not seem to capture anchor tag info.

No surprise. In the HTTP protocol, the character # is a URL delimiter. The part #thisPageSection, so-called fragment identifier in HTTP terms, is just for the scrolling convenience of the browser. The browser does not send it to the web server. That is why you cannot access it via CGI. As you have already discovered, the answer is to use Javascript.




Participant
January 25, 2007
I wanted to piggyback on this question, because I have a similar problem.

I have used the CGI variables to get the info you mentioned. However, it does not seem to capture anchor tag info.

Consider the following:

http://mydomain.com/foo/bar/page.cfm?var=blah#thisPageSection

The last part is not captured by the cgi.query_string, nor anywhere else, that I can figure out.

Does anyone have any advice on how to get the full url, for redirect purposes? I know I can do it via Javascript, but was trying to keep it all within CF logic, if possible.

Tx,

Kendra
January 18, 2007
Thank you bkbk and Adam. In this case it's http, and the above script works perfectly well! You're remaks are taken under consideration Adam. Thanks!
Inspiring
January 18, 2007
> <cfoutput>#" http://" & CGI.HTTP_HOST & CGI.SCRIPT_NAME & IIf(len(trim(CGI.QUERY_STRING)),DE('?'),DE('')) & CGI.QUERY_STRING#</cfoutput>

Unless it's HTTPS, or running on a port other than 80... ;-)

I don't have access to an HTTPS-running server @ present, otherwise I'd
provide a more helpful answer. However there are two additional CGI
variables which get set to (something) if the request was made via HTTPS.

To deal with the port, there is CGI.SERVER_PORT. If it's other than 80 (or
443 if HTTPS), the one should include a colon and the port number after the
HTTP_HOST value.

--
Adam
BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
January 18, 2007
<cfoutput>#" http://" & CGI.HTTP_HOST & CGI.SCRIPT_NAME & IIf(len(trim(CGI.QUERY_STRING)),DE('?'),DE('')) & CGI.QUERY_STRING#</cfoutput>