cfhttp from application.cfm?
Hi Gang-
I inherited some code that I'm trying to clean up and get production-ready.
Because of conditions I can't change I'm looking for a short term solution for the following:
The application in question was originally written with web server url rewriting on IIS 6 and CF8, among other things that are no longer supported.
I finally configured the application so that the home page loads but here's the rub: The app was originally architected with all of its links in the folder "/webroot/links/" however thanks to url rewriting the "/links/" never appeared in the urls - they were previously hidden from the urls thanks to url rewriting. (The new server won't have the url rewriting). Because of this I have to manaully change all the links/hrefs in the code to run from
"http://localhost/subjectmatter/" to "http://localhost/links/subjectmatter", which isn't desireable, but a fix for now.
I wrote the following code to drop into the application.cfm file of the app so that all page requests could be checked. The problem? This code won't run from the application.cfm, it seems to run from any other page I manually paste it into but when it's in application.cfm it just times out with no error message. Anyone have any ideas why this times out inside of application.cfm but not when called otherwise?
START CODE
<!--- REQUEST CHECKER: CHECK THE REQUESTED URL FOR 404 BECAUSE OF MISSING "/LINKS" IN URL. IF TRUE REDIRECT REQUEST BUT WITH ADDED "/LINKS" IN URL. --->
<!--- put the requested url into a var called "testUrl" --->
<cfset requestedUrl="http://"&"#server_name#"&"#cgi.PATH_INFO#">
<!--- Attempt to retrieve the testURL --->
<cfhttp method="head" url="#requestedUrl#" resolveurl="no" throwonerror="no" />
<!--- Check status code returned and is 404 --->
<cfif IsDefined("cfhttp.responseheader.status_code")>
<cfif cfhttp.responseheader.status_code EQ "404">
<!--- if the requested url doesn't contain "links" as the first subdirectory --->
<cfif #listFirst(cgi.PATH_INFO,"/")# IS NOT "links">
<!--- Attempt to retrieve the requested url with "/links" added to the requested file path --->
<cfset newUrl="http://"&"#server_name#"&"/links"&"#cgi.PATH_INFO#">
<cfhttp method="head" url="#newUrl#" resolveurl="no" throwonerror="no" name="newUrlCheck" />
<cfif IsDefined("newUrlCheck.responseheader.status_code") AND newUrlCheck.responseheader.status_code NEQ "404">
<cflocation url="#newUrl#">
<cfelse>
404 from application.cfm: PAGE NOT FOUND!
<cfabort>
</cfif>
<cfelse>
Requested url already contains "links"!
</cfif>
</cfif>
</cfif>
END CODE
Thanks in advance for your help!
Rich
