Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7002875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:59:09+00:00 2026-05-27T20:59:09+00:00

I am using ColdFusion 9.0.1 I have a new site that is accessible through

  • 0

I am using ColdFusion 9.0.1

I have a new site that is accessible through a few domains such as:

mydomain.com
www.mydomain.com
foo.mydomain.com

For SEO and tracking purposes, I want to make sure that only “mydomain.com” is indexed and accessed. So, every request that tries to access my site through other domains will be 301 directed to “mydomain.com”.

I want to make sure that I capture and preserve the query string so that I don’t just send people to the home page.

I will also make sure that I can access the site locally at 127.0.0.1

I wondering where in the code is the best place to do this SPECIFIC type of redirect. My guess it’s in application.cfc near the top, in the onRequestStart() method.

Is this best place to put the code and does is this code complete? Is there a better way to code this?

<cfscript>
ThisHost = CGI.HTTP_HOST;
QString = CGI.QUERY_STRING;
GoToURL = "http://mydomain.com?" & QString;
if (ThisHost != "mydomain.com" && ThisHost != "127.0.0.1") {
    writeOutput("<cfheader statuscode='301' statustext='Moved permanently'>");
    writeOutput("<cfheader name='location' value='#GoToURL#'>");
    abort;
}
</cfscript>

UPDATE

I know this isn’t the best way to accomplish what I need, because this task is much better suited to the web server’s skill set. Here’s my code till I can implement this on the web server:

<cfscript
ThisHost = CGI.HTTP_HOST;
QString = CGI.QUERY_STRING;
GoToURL = "http://flyingpiston.com/?" & QString;
if (ThisHost != "flyingpiston.com" && ThisHost != "127.0.0.1:8500") {
    location(GoToURL, false, 301);  
}
<cfscript
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:59:09+00:00Added an answer on May 27, 2026 at 8:59 pm

    I agree with other comments and answers that doing this at the web server is a better solution. I would also point out that if you want to use the script syntax, this is entirely wrong and will simply return a string to the browser:

    writeOutput("<cfheader name='location' value='#GoToURL#'>");
    

    In ColdFusion 9, you would instead use the location() function:

    location("url", addtoken, statusCode);
    

    In your case:

    location(GoToURL, false, 301);
    

    Your GoToURL variable is also missing the page name, so you’d need to add CGI.SCRIPT_NAME into the mix just before the ? to get the full URL being called.

    With the tag syntax (as of ColdFusion 8 I believe), there is no need to use the CFHEADER tag for a 301 redirect. The CFLOCATION tag now supports a statuscode attribute which can be set to 301 as needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ColdFusion 9.0.1. I have a new web site that uses Bikes.cfm
I am using this new jQuery plugin called jsTree www.jstree.com and using the HTML
I have an old site built in Coldfusion, a new site built in Rails.
I am pretty new to ColdFusion ORM and I have some questions that I
I'm using Coldfusion ORM (Hibernate), and have a cfc mapped to a database table.
I have included numerous coldfusion and html files in CFM pages using the <cfinclude>
I have a webservice programmed in coldfusion which I'm attempting to consume using c#.net.
I have a web application, written in ColdFusion, which periodically starts using 100% of
I'm using ColdFusion to populate a template that includes HTML unordered lists ( <ul>
I have a coldfusion 8 webservice that returns an array <cffunction access=remote name=testMethod returntype=array>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.