|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
HTTP 301 redirects using CFHTTP?
Author: Pete Ruckelshaus
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:47057#248374
I'm rolling out a newly redesigned site and need to implement a bunch
of redirects that return an HTTP response code of 301 (Moved
Permanently). There will be a database table (loaded into memory)
that will have the bad & good URL's. Has anyone here done this,
specifically the redirect that results in a 301 response code?
Thanks,
Pete
Author: James Holmes
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:47057#248376
CFHTTP has no place in this.
You need CFHEADER if you are doing it via CF.
> I'm rolling out a newly redesigned site and need to implement a bunch
> of redirects that return an HTTP response code of 301 (Moved
> Permanently). There will be a database table (loaded into memory)
> that will have the bad & good URL's. Has anyone here done this,
> specifically the redirect that results in a 301 response code?
--
CFAJAX docs and other useful articles:
http://www.bifrost.com.au/blog/
Author: Pete Ruckelshaus
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:47057#248391
OK, thanks James, that was the shove in the right direction that I
needed. In case anyone else is looking for the same answer, here's my
test code that works:
<cfscript>
qryRedirect = queryNew("oldurl,newurl","varchar,varchar");
tmp = queryAddRow(qryRedirect);
tmp =
querySetCell(qryRedirect,"oldurl","http://localhost/test/404/nothere.html");
tmp =
querySetCell(qryRedirect,"newurl","http://localhost/test/404/goodurl.cfm");
attemptedURL = "http://" & CGI.server_name & CGI.script_name;
generatedURL = getToken(CGI.query_string, 2, ";");
</cfscript>
<cfquery name="checkURL" dbtype="query">
SELECT newurl
FROM qryRedirect
WHERE oldurl = '#generatedURL#'
</cfquery>
<cfif checkURL.recordcount EQ 1>
<cfheader name="Location" value="#checkurl.newurl#">
<cfheader statuscode="301" statustext="Moved Permanently">
<cfelse>
<cflocation url="/404.cfm">
</cfif>
Ultimately I will have the redirects in a database which I will load
into memory (via the application scope) for faster access. Memory
usage won't be an issue, there's only 100 or so URL's to redirect. If
anyone sees any issues with this code, please let me know.
Thanks,
Pete
Author: Russ
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:47057#248414
If there are going to be only 100 URL's, and they are not going to change
often, and you have access to the server, I would suggest doing it in apache
or even IIS, as that's going to take a lot of load off your cf server...
You can generate the rules using cf from the db, write it to a file and then
have apache or iis rewrite use it...
Russ
----- Excess quoted text cut - see Original Post for more -----
|
March 18, 2010
|
Latest Fusion Authority Articles
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||