If someone requests a non existent .cfm page, I’d like to send them to a custom 404 page.
Lucee Admin > Settings > Error > Missing Template Error (404)
I’ve set a custom 404.cfm page there, but I’m not sure what variable to use to display the url the user requested.
ie. mypage.com/doesntexist.cfm
I want to show the user ‘mypage.com/doesntexist.cfm’. What variable to do I use to get that info? ‘cgi.server_name’ is only giving me the host name.
Thanks!
I found this code that seems to work. Is there a better way?
<cfoutput>http<cfif cgi.https is "on">s</cfif>://#cgi.server_name &
cgi.script_name#<cfif
len(trim(cgi.query_string))>?#cgi.query_string#</cfif></cfoutput>
you can omit the http or https and just use a protocol relative url like “//#cgi.server_name##cgi.script_name#”
or even just #cgi.script_name#
https://www.paulirish.com/2010/the-protocol-relative-url/
also remember that cgi variables are user provided so they should be escaped like form or url variables
2 Likes