I had to change the domain of a longstanding ColdFusion site with hundreds of pages. With .htaccess on an Apache Linux host this is easy and well documented. With ColdFusion on IIS when you are not a full administrator of the IIS server…. not so much. My searches found post after post with the same instruction, how to redirect an individual page or an entire domain to one single new URL. Whaaatttt!? Why you no care about your customers and visitors!
Adobe cflocation doc – not exactly chocked full of details
Google returns a lot of sites with the simple but not very helpful nuclear option:
1 2 | <cfheader statuscode="301" statustext="Moved permanently"> <cfheader name="Location" value="http://www.newlocation.com"> |
Then I found a rare post on Katzwebservices with details on how to redirect a single page, prefix all pages with www or https and how to properly redirect an entire website:
https://katz.co/coldfusion-redirects/
The Author of the code gives a shout to Ben Nadel and can be found in the comments here:
http://www.bennadel.com/blog/378-Getting-The-Requested-URL-From-The-Page-Request-Object-Servlet-Without-Using-CGI.htm
I used the code there and ended up with the below to redirect all pages from an existing site and forums on domainA to domainB. Google picked it up within 2 days and all pages are now listed with domainB.com. Thank you Ben Zadel and Zack Katz!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <!--- If site is www.domainA.com ---> <cfif (CGI.SERVER_NAME EQ "www.domainA.com")> <!--- Save the URL (and $_GET variables too) as the string 'strUrl' ---> <cfset strUrl = CGI.script_name & "?" & CGI.query_string /> <!--- Use 301 for SEO-friendly redirects ---> <cfheader statuscode="301" statustext="Moved permanently"> <!--- Redirect to new website (this case, added www.) with strUrl added on ---> <cfheader name="Location" value="http://www.domainB.com#strUrl#"> </cfif> <!--- If site is domainA.com ---> <cfif (CGI.SERVER_NAME EQ "domainA.com")> <cfset strUrl = CGI.script_name & "?" & CGI.query_string /> <cfheader statuscode="301" statustext="Moved permanently"> <cfheader name="Location" value="http://www.domainB.com#strUrl#"> </cfif> |