SEO - 301 redirect

webactor

Avatar: webactor

2011-05-25 18:27

Hi there

I have a small question about 301 redirect and where to put it.
Ex. I would like til make a 301 redirect from a www. to a non-www domain.

I found out that the code from non-www to www is:
----------------------------------------------------------------------------------------------
<?php
if (substr(getenv('HTTP_HOST'),0,3) != 'www')
{
header('HTTP/1.1 301 Moved Permanently');
header('Location:http://www.'.$_SERVER['HTTP_HOST'].
$_SERVER['REQUEST_URI']);
}
?>
----------------------------------------------------------------------------------------------
And i put that into my index.php file in my root dir.

But what do i do if its the other way around (from www to non-www) ?
HTACCESS IS NOT AN ISSUE !! It has to be in php code.

Also - did i put the code above into the right file ?
According to the link below - i did it right

I Just cant find a way to redirect the other way around
Hope you can help me


You can check your 301 - code here:
http://www.ragepank.com/redirect-check/


C yaaaa - Cheers

» Quick.Cms v2.x

Kimo

webactor

Avatar: webactor

2011-05-26 11:07

Ohhh Got it

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.somesite/some-page/");
?>

Put this into the top of your index.php

C yaaaa + Cheers

Kimo

webactor

Avatar: webactor

2011-05-26 11:19

Okay i must admit i works better with .htaccess

With
-------------------------------------------------------------------
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

-------------------------------------------------------------------

C yaaaa + Cheers

Kimo

Back to top
about us | contact