Prakash
Prakash

Reputation: 21

Redirecting webpage using URL parameters

I am trying to redirect a webpage depending on the URL parameters. I have gone through so many tutorials and stackflow answers in the last couple of days without finding a way past this. I am not a programmer but learnt everything i know about php and html coding using stackflow.So thanks you everyone.

www.domain.com/women/product?id=08607080

would like to redirect to

  www.domain.com/women/Accessories/product?id=08607080

this is the code I am using now but it directs to www.dmail.com/women

Help please

<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/womenconfig.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.inc.php';

mysql_connect(HOST, USERNAME, PASSWORD) or die(mysql_error());
mysql_select_db(DB) or die(mysql_error());

$ArtNumber = isset($_GET['id'])?$_GET['id']:Null; 

$ArtNumber = isset($_GET['id'])?$_GET['id']:Null; 
$query = "(SELECT * FROM " . implode(' WHERE ArtNumber=\'' . $ArtNumber . '\') UNION (SELECT * FROM ', array_keys($shops_arr)) . '  WHERE ArtNumber=\'' . $ArtNumber . '\' ) ';

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);


    $ArtNumber  = $row['ArtNumber'] ;
    $ProductCategory1   = $row['ProductCategory1'] ;
    $ProductCategory2   = $row['ProductCategory2'] ;
    $ProductCategory3   = $row['ProductCategory3'] ;



    echo "<script>window.location = ''/women/Accessories'.$ProductCategory1.'/product?id=',$ArtNumber,''</script>";

?>

Upvotes: 0

Views: 122

Answers (2)

seeker
seeker

Reputation: 3333

As @arkassha said you should set up proper HTTP header (Location: url) or use web server capabilities. Here is example of redirection via location header:

<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/womenconfig.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.inc.php';

mysql_connect(HOST, USERNAME, PASSWORD) or die(mysql_error());
mysql_select_db(DB) or die(mysql_error());

$ArtNumber = isset($_GET['id'])?$_GET['id']:Null; 

$ArtNumber = isset($_GET['id'])?$_GET['id']:Null; 
$query = "(SELECT * FROM " . implode(' WHERE ArtNumber=\'' . $ArtNumber .    '\') UNION (SELECT * FROM ', array_keys($shops_arr)) . '  WHERE ArtNumber=\'' .   $ArtNumber . '\' ) ';

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);


$ArtNumber  = $row['ArtNumber'] ;
$ProductCategory1   = $row['ProductCategory1'] ;
$ProductCategory2   = $row['ProductCategory2'] ;
$ProductCategory3   = $row['ProductCategory3'] ;


header("Location: /women/Accessories/product?id=$ArtNumber");
?>

One thing to note here that headers must be sent before any contents.

As of second variant in case of apache you could use rewrite rules: http://kb.mediatemple.net/questions/85/Using+.htaccess+rewrite+rules#gs

It is also possible to redirect via javascript as you mentioned but that is not the preferred solution.

Upvotes: 1

DevLee
DevLee

Reputation: 336

 window.location.replace(" ''/women/Accessories'<?php echo "{$ProductCategory1}'/product?id={$ArtNumber}'' "; ?>");

please try this.

Upvotes: 1

Related Questions