Top SEM and SEO Tips    

Search Engine Friendly 301 Redirect in CFM Coldfusion

January 18, 2006 – 3:00 am

If you are finding that the www.sitename.com and sitename.com version of your site are both being indexed by the search engines you could hit an issue with the search engines seeing duplicate content - after all most sites have both site names resolving to the same underlying file structure. This can also be an issue for people with parked domains - if you’ve brought multiple domains with the common misspellings of your company name (for example), if the search engines index the parked domain you could have a duplicate content issue. Another issue is having links pointing to the various site names dilutes their value, but pointing them all at just one domain name you’ve got a better chance of higher rankings.

One of the best ways around this issue is to redirect all traffic destined for the domains you don’t want to get indexed to the site name you do want to get indexed. By using a 301 redirect the value of the links will also be redirected to the main site name.

Coldfusion CFM 301 Code

Place the following code into the header of any CFM document and it will redirect the page access to the correct site name. while preserving the script name and the query arguments.

<!-- If the server name is not www.sitename.com we can do the redirect to www.sitename.com.
  ' The only time we can is if the method is a GET
  ' (no way to pass along the POST arguments) and its on port 80 (don't want to redirect the SSL).
-->
<cfif CompareNoCase(  CGI.SERVER_NAME , "sitename.com") is 0 AND
	CGI.SERVER_PORT is 80 AND
	CompareNoCase(  CGI.REQUEST_METHOD , "get") is 0 >
<cfheader statuscode="301" statustext="Moved permanently">
<cfif CGI.QUERY_STRING IS NOT "" >
		<cfheader name="Location" value="http://www.sitename.com#CGI.SCRIPT_NAME#?#CGI.QUERY_STRING#">
<cfelse>
		<cfheader name="Location" value="http://www.sitename.com#CGI.SCRIPT_NAME#">
	</cfif>
</cfif>

Related

 

PHP 301 Redirect
ASP 301 Redirect
CFM Coldfusion 301 Redirect
JSP Java Server Pages 301 Redirect
404 Redirect one file at a time
404 Redirect one directory at a time
404 Redirect multiple pages easily

  1. 2 Responses to “Search Engine Friendly 301 Redirect in CFM Coldfusion”

  2. I placed your 301 redirect code on our home page, just as you outline here. It works great. However, when doing a header check, the result comes back as a HTTP/1.1 302 Object Moved.

    This is NOT a 301 redirect then….its a 302.

    Anyone have any ideas or thoughts on this?

    By Pete Radke on May 30, 2008

  3. The code
    <cfheader statuscode=”301″ statustext=”Moved permanently” >

    sets the return code to 301 - ensure that it is in correctly.

    Note if you’re cutting and pasting the code the quotes are being converted to smart quotes. Try hand coding.

    By admin on Jul 3, 2008

Post a Comment