Jump to content

404 redirecting to a search page


etrader

Recommended Posts

You should be able to break apart the URL with explode():

 

//GET THE CURRENT URL
$url = $_SERVER['PHP_SELF'];

//BREAK APART THE URL
$urlPieces = explode('/', $url);

//LOOP THROUGH THE URL PIECES
foreach($urlPieces as $currPiece) {
    echo "<li>$currPiece</li>";
}

 

 

You'll need to replace the echo statement in the foreach loop with whatever formatting you need to get the search query. Then just redirect the page.

Thanks for your kind assistance. My problem is that

$url = $_SERVER['PHP_SELF'];

considers the error page at "http://mysite.com/404.php" instead of the misspelled url.

 

For example, if someone write "http://mysite.com/something-wrong.html",

$url = $_SERVER['PHP_SELF'];
echo $url;

will show "http://mysite.com/404.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.