...

View Full Version : How do I add a 301 php variable redirect in an existing file?



janaro
06-23-2010, 09:16 PM
How could I redirect a php variable on an existing/working index.php file. I only want to redirect the variable(s).


I would like the redirect a series of variables (?option):
-index.php?option=com_content&task=view&id=70&Itemid=40 to point to folder1
-index.php?option=com_content&task=view&id=70&Itemid=42 to point to folder2
etc


Could it be a little like this?

<?php
if(isset($_GET['option']) && $_GET['option'] == "?option=com_content&task=view&id=70&Itemid=40 "))
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/folder1");
// at this point you should not really use exit .
}
if(isset($_GET['option']) && $_GET['option'] == "?option=com_content&task=view&id=70&Itemid=41 "))
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/folder2");
// at this point you should not really use exit .
}
?>

Would I have to paste that into the fully working index.php?

Many thanks for the help!

Dormilich
06-24-2010, 08:19 AM
// at this point you should not really use exit .

why ?

janaro
06-24-2010, 02:13 PM
I got this code from a friend who new how to create a redirect between one location and the other....

Can you help with redirecting my variable?

Thanks

DJCMBear
06-24-2010, 02:21 PM
For starters you code has loads of errors, such as the $_GET['option'] var cant equal the string as you cant use the $_GET var to get the full query string you would need to use $_SERVER['REQUEST_QUERY'].

Secondly are you trying to make all prams equal something then redirecting to the url for them prams?

janaro
06-24-2010, 07:24 PM
Hi,
I'm open to changing it or starting from zero (I'm not much of a coder).

I familiar with the:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/newpage.html");
exit();
?>

And then to save as the oldpagename.php

But what code would I have to insert into my already working index.php to redirect may variables to it's corresponding pages or folders?

DJCMBear
06-25-2010, 12:39 AM
are you using any form of storage such as a mysql database to store information into?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum