Here is small code to make your WordPress Search Result more friendly for SEO (Search Engine Optimization). It will result http://www.shouthuns.com/search/find-something/ instead http://www.shouthuns.com/?s=find+something
Just put this code into top of the header of your themes. (Remember! It should be placed on first line on your header themes)
<?php
$src = strtolower(mysql_real_escape_string($_GET['s']));
$sclear = ereg_replace("[^ 0-9a-zA-Z]", " ", $src);
// Remove multiple spaces
while (strstr($sclean, " ")) {
$sclear = str_replace(" ", " ", $sclear);
}
// Replace spaces with a URL friendly + sign
$sclear = str_replace(" ", "-", $sclear);
// If valid then redirect to the URL rewritten search page
if ($sclear != '') {
header( 'Location: http://www.shouthuns.com/search/'.$sclear.'/' );
}
?>
$src = strtolower(mysql_real_escape_string($_GET['s']));
$sclear = ereg_replace("[^ 0-9a-zA-Z]", " ", $src);
// Remove multiple spaces
while (strstr($sclean, " ")) {
$sclear = str_replace(" ", " ", $sclear);
}
// Replace spaces with a URL friendly + sign
$sclear = str_replace(" ", "-", $sclear);
// If valid then redirect to the URL rewritten search page
if ($sclear != '') {
header( 'Location: http://www.shouthuns.com/search/'.$sclear.'/' );
}
?>
Before you try on your blog, please play around here first! Then, lets try on your blog now! And enjoy your new pretty searching result url!
Hopefully this article is useful :) Thanks for reading.
Related posts: