How do I make a redirect?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
~sikka~
Forum Newbie
Posts: 6
Joined: Thu Apr 28, 2005 8:19 am

How do I make a redirect?

Post by ~sikka~ »

I need a redirect from http://www.norskstabbursmat.no to http://www.norskstabbursmat.no/kurv/
can anyone tell me how to do this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

.htaccess (with mod_rewrite) or using php's header() function.
~sikka~
Forum Newbie
Posts: 6
Joined: Thu Apr 28, 2005 8:19 am

Post by ~sikka~ »

ehh ok... I wish I could do that - can you spell it out for me?
Gambler
Forum Contributor
Posts: 246
Joined: Thu Dec 08, 2005 7:10 pm

Post by Gambler »

Code: Select all

header("Location: www.norskstabbursmat.no/kurv/");
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remember to use a full URL.. http:// and all.
~sikka~
Forum Newbie
Posts: 6
Joined: Thu Apr 28, 2005 8:19 am

Post by ~sikka~ »

ok I went to my index.php file and in the header I put this code:

Code: Select all

<?php header("Location: http://www.norskstabbursmat.no/kurv/");?>
And I got this error msg:
Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/nstab/norskstabbursmat.no/index.php:10) in /hsphere/local/home/nstab/norskstabbursmat.no/index.php on line 25
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the redirection must happen before any output is sent to the requesting agent.

Read here: viewtopic.php?t=1157
~sikka~
Forum Newbie
Posts: 6
Joined: Thu Apr 28, 2005 8:19 am

Post by ~sikka~ »

I dont understand - I even get the error msg if I have my php-file containing only that string tho.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you likely have a space or something before. These errors can easily happen between inclusions where you may have a trailing space or leading space (possibly a carriage return.)
~sikka~
Forum Newbie
Posts: 6
Joined: Thu Apr 28, 2005 8:19 am

Post by ~sikka~ »

Thank you! It was ONE space before my code :roll:
But now its working! :mrgreen: :mrgreen:
Post Reply