301 Redirect Question
Posted: Sat Sep 12, 2009 10:26 pm
Hello, I hope to be an active contributor to your site. I have a 301 question about redirects and can't seem to find an answer. We use a bit of code to redirect one of our URL's to a new search engine friendly version.
See here:
http://www.seatkarma.com/search.php?query=Mary+Poppins
Redirects to:
http://www.seatkarma.com/search.php/Mary-Poppins
Here is the code that we are using to do it:
Here is the Problem: We used to use an underscore (_) to separate words in our query and as a result we have many URL's in the search engines that are duplicate. For example:
http://www.seatkarma.com/search.php/Mary-Poppins
has a duplicate at
http://www.seatkarma.com/search.php/Mary_Poppins
The search engines don't like duplicate content much, so we want to resolve this by permanently redirecting any requests for http://www.seatkarma.com/search.php/Search_Term
to http://www.seatkarma.com/search.php/Search-Term
Can this be done by modifying the code above somehow? Please advice. Thanks!
See here:
http://www.seatkarma.com/search.php?query=Mary+Poppins
Redirects to:
http://www.seatkarma.com/search.php/Mary-Poppins
Here is the code that we are using to do it:
Code: Select all
if (strlen($_GET['query'])) {
$query = trim(strtr($_GET['query'], ' ', '-'));
header('Location: /search.php/'.urlencode($query), true, 301);
exit();
}
$query = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], 'search.php/') + 11);
$query = strtr($query, '_', ' ');
$query = strtr($query, '-', ' ');
$query = trim($query);
if (strlen($query) == 0) {
header('Location: /index.php?message=emptyQuery');
exit();
}
http://www.seatkarma.com/search.php/Mary-Poppins
has a duplicate at
http://www.seatkarma.com/search.php/Mary_Poppins
The search engines don't like duplicate content much, so we want to resolve this by permanently redirecting any requests for http://www.seatkarma.com/search.php/Search_Term
to http://www.seatkarma.com/search.php/Search-Term
Can this be done by modifying the code above somehow? Please advice. Thanks!