Marthinus Strydom
Marthinus Strydom

Reputation: 267

How to do a 301 redirect using Coldfusion from www to http

I did one of these online SEO analysis checks on a website I am building. One of the issues identified is:

WWW redirection (301): no For search bots website addresses with www and without it are considered as different pages. Adding redirection help you avoid double content panelty.

In my current .htaccess file I have the following:

# lose the www
RewriteCond %{http_host} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,NC]

I am not sure if the issue identified relates to the .htaccess file or something else?

I am using Coldfusion and all the searches I have done refers to 301 redirection but it seems that this relates to specific pages that need to be permanently redirected?

The code that I have found for Coldfusion 301 redirection is the following:

<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="http://www.example.com/coldfusion/tutorial">
<cfabort>

My question is how do I set up the 301 redirection as identified above? Do I add the coldfusion 301 redirection as per the code above, and if so how do I use it to redirect users from www.example.com to http://example.com?

Or, must this be done in the .htaccess file and how should I structure it?

Hope this is clear?

So, in summary, how do I fix this problem:

WWW redirection (301): no For search bots website addresses with www and without it are considered as different pages. Adding redirection help you avoid double content panelty.

Upvotes: 0

Views: 271

Answers (1)

Marthinus Strydom
Marthinus Strydom

Reputation: 267

The method was not correct. This is the correct way to redirect from www to http.

RewriteEngine on

# lose the www
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

It is working perfectly now.

Upvotes: 1

Related Questions