PHP重定向,怎么样?

For some reason one magento url is not working fine on my website. see here: Integrity constraint violation: 1052 Column 'position' in order clause is ambiguous

So, I decided that I could do a redirect for this failing url: I tried with apache but it doesnt work see here: Apache simple redirect from one page to a second one

They suggested to do it with php

can someone pls explain me how to do this with php?

something like

if url = 'myfaliingurl' then
  redirect to new url

thats it

this is what I tried in apache

Redirect 301 http://www.theprinterdepo.com/catalogsearch/result/index/?cat=100&q=1022&x=0&y=0 http://www.theprinterdepo.com/catalogsearch/advanced/result/?name=1022&sku=&price%5Bfrom%5D=&price%5Bto%5D=&free_shipping=&category=100

Update 1:

Its not working, I put this on index.php at the end.

if($url == 'http://www.theprinterdepo.com/catalogsearch/result/index/?cat=100&q=1022&x=0&y=0')
  {
          header('location:http://www.theprinterdepo.com/catalogsearch/result/index/?cat=100&q=1022&x=0&y=0 http://www.theprinterdepo.com/catalogsearch/advanced/result/?name=1022&sku=&price%5Bfrom%5D=&price%5Bto%5D=&free_shipping=&category=100');
          exit();
  }
else
{
Mage::run('printerdepo','website');
}

Using this code you get

 <?php
  if($url == 'myfaliingurl')
  {
          header('location:http://www.theprinterdepo.com/catalogsearch/result/index/?cat=100&q=1022&x=0&y=0 http://www.theprinterdepo.com/catalogsearch/advanced/result/?name=1022&sku=&price%5Bfrom%5D=&price%5Bto%5D=&free_shipping=&category=100');
  }
  else{
          header('location:otherposition');
  }
  ?>

If you just want to use PHP you can use header()

header("Location: http://www.example.com/"); /* Redirect browser */

so:

if (/*whatever you're checking*/){
    header("Location: http://www.example.com/"); /* Redirect browser */
    exit();
}

In PHP you can use the header() function to redirect a request:

header('Location: http://www.example.com/');

http://php.net/manual/en/function.header.php

What you need is written like this: Remember not to output anything before the php header() function.

$url = "myfailingurl";
$newurl = "http://www.mynewurl.com/blabla";

if ($url == "myfailingurl"){
     header("Location: $newurl"); die();
}

More details about the header() function here: http://php.net/manual/en/function.header.php

With PHP is like this:

<?php
header('Location: http://www.example.com/');
// if you get a header error, which is really frequent, try with javascript like this:
echo '<script type="text/javascript">window.location ="http://www.example.com";</script>';
?>
if(url == 'myfaliingurl')
   redirect('newUrl');


function redirect($url)
{
   header("Location: $url");
}