Forum Moderators: coopster

Message Too Old, No Replies

PHP created page 301 redirect - please help

         

apeepa

4:28 am on Nov 25, 2008 (gmt 0)

10+ Year Member



I've usually had no problem applying redirects in htaccess file, i need to redirect a dynamic created php code

this is what i wrote - but it doesn't work. how could i get this sample below to permanently redirect

redirect 301 /card_details.php?cardid=74 http://www.example.com/card_details.php?cardid=84

thank you all

[edited by: dreamcatcher at 12:30 pm (utc) on Nov. 25, 2008]
[edit reason] use example.com. Thanks. [/edit]

eeek

4:51 am on Nov 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



All you need is a header() call and and exit.

apeepa

5:18 am on Nov 25, 2008 (gmt 0)

10+ Year Member



do you mean in the card_details.php page? do you mean I can't do it in the htaccess file?

any detailed help would be greatly appreciated, i am a php noob

eeek

5:37 am on Nov 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



do you mean I can't do it in the htaccess file?

This is the PHP forum. Using .htaccess wouldn't be on topic here. If you want to redirect from a PHP script, just use the header() function (see the docs for how it's used) in your code. Otherwise, please explain "i need to redirect a dynamic created php code" a bit better.

Anyango

6:31 am on Nov 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in card_details.php page (top of file)

if($_GET["cardid"]==74)
{
header("Location: http://www.example.com/card_details.php?cardid=84");
exit;
}

[edited by: Anyango at 6:32 am (utc) on Nov. 25, 2008]

[edited by: dreamcatcher at 12:30 pm (utc) on Nov. 25, 2008]
[edit reason] use example.com. Thanks. [/edit]

apeepa

12:06 pm on Nov 25, 2008 (gmt 0)

10+ Year Member



thank you, would the search engine view this as a 301 redirect for that page or a 200?

Receptional Andy

12:20 pm on Nov 25, 2008 (gmt 0)



For it to be a permanent (301) redirect, you need an additional header:

header ('HTTP/1.1 301 Moved Permanently');
header("Location: http://www.example.com/example.php?id=84");

apeepa

12:46 pm on Nov 25, 2008 (gmt 0)

10+ Year Member



Thank you andy - but in my example, I only have card_details.php as my page. Though If I would add the code as you have it, I would redirect all of the variations. I only need to 301 redirect /card_details.php?cardid=74 to go there.

apeepa

12:48 pm on Nov 25, 2008 (gmt 0)

10+ Year Member



do you mean it should look like:

in card_details.php page (top of file)

if($_GET["cardid"]==74)
{
header ('HTTP/1.1 301 Moved Permanently');
header("Location: http://www.example.com/card_details.php?cardid=84");
exit;
}

?

Receptional Andy

1:05 pm on Nov 25, 2008 (gmt 0)



Yes :)

If you don't include the 301 header it will default to a 302 redirect which is unlikely to achieve what you want.

apeepa

1:10 pm on Nov 25, 2008 (gmt 0)

10+ Year Member



Andy,

you're great! thank you for all your help