| Author |
Permanent redirect via header() function ?
|
|
|
| Hi,
I sometimes need to replace a page but make sure a new page is loaded
instead,
e.g.:
<?php
header("Location: newpage.php");
?>
I was wondering if I can add to this command somehow that the client knows
this is a permanent redirect ?
Permanent is ... error 301 ... right ?
Or should I do this in .htaccess somehow ?
| |
| nick.denardis@gmail.com 2006-09-10, 6:57 pm |
| If this is truly a permanent redirect and you do not need to execute
any PHP code i think doing it in a htaccess file would be the way to
go. This way the user will be redirected by the server before it gets
to the actual file, there is less overhead on the server end to parse
the php file just to redirect. Although if you needed to run some PHP
before the redirect happens then you can set in the header:
<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>
Or in a .htaccess file:
redirect 301 /old/old.htm http://www.you.com/new.htm
Peter wrote:
> Hi,
> I sometimes need to replace a page but make sure a new page is loaded
> instead,
> e.g.:
>
> <?php
> header("Location: newpage.php");
> ?>
>
> I was wondering if I can add to this command somehow that the client knows
> this is a permanent redirect ?
> Permanent is ... error 301 ... right ?
>
> Or should I do this in .htaccess somehow ?
| |
|
| > <?php
> Header( "HTTP/1.1 301 Moved Permanently" );
> Header( "Location: http://www.new-url.com" );
> ?>
>
Thanks.
You use a hard coded URL instead of the relative one that I use.
E.g.
header("Location: newpage.php");
or:
header("Location: ..\newpage.php");
Will that influence things ?
Or will the permanent redirect error (301) be understood just the same ?
| |
| nick.denardis@gmail.com 2006-09-10, 6:57 pm |
| It should be understood the same, the 301 just tells the server that
the page is no longer going to be located there anymore.
Peter wrote:
>
> Thanks.
> You use a hard coded URL instead of the relative one that I use.
> E.g.
> header("Location: newpage.php");
> or:
> header("Location: ..\newpage.php");
>
> Will that influence things ?
> Or will the permanent redirect error (301) be understood just the same ?
|
|
|
|