1

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');
}

6 Answers 6

5

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();
}
Sign up to request clarification or add additional context in comments.

Comments

2

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');
  }
  ?>

6 Comments

should I put this on index.php?
shold I also put exit() as other said?
yeah, anywhere you want because it's base on condition!
there are no required exit() because whenever redirect then after header code that will never execute!!!
Of course you need exit(). The code will continue executing, even though the header was sent. The fact that you send the header has nothing to do with the rest of the script.
|
0

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

2 Comments

I dont know php syntax, please elaborate the answer more.
The manual I linked to explains it perfectly. You just need to include that line wherever/whenever you want it to redirect.
0

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>';
?>

Comments

0
if(url == 'myfaliingurl')
   redirect('newUrl');


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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.