/ Forside / Teknologi / Udvikling / PHP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
PHP
#NavnPoint
rfh 3959
natmaden 3372
poul_from 3310
funbreak 2700
stone47 2230
Jin2k 1960
Angband 1743
Bjerner 1249
refi 1185
10  Interkril.. 1146
301 redirect in Php
Fra : Webactor


Dato : 25-05-11 10:35

Hi there

I have a small question about 301 redirect
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']);
}
?>
----------------------------------------------------------------------------------------------
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.

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
kimo

 
 
Karl Erik Christense~ (25-05-2011)
Kommentar
Fra : Karl Erik Christense~


Dato : 25-05-11 19:04

On 25-05-2011 18:34, Webactor wrote:
> Hi there
>
> I have a small question about 301 redirect
> 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']);
> }
> ?>
> ----------------------------------------------------------------------------------------------
> 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.
>
> 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
> kimo

You could take a look at substr_replace:

substr_replace ( $string , $replacement , $start, $length )

substr_replace (getenv'HTTP_HOST' , '' , 1 , 4 )

Karl Erik.

--
http://dmwebdesign.dk - DM i Webdesign
http://ranunkelvej.com/b&o/ - Reparation af B&O Red Line højttalere
http://webdesign.ranunkelvej.com - Artikler om webdesign

Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408914
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste