I am using MySQL and the 'like' query in order to find pages. I need to be able to do things this way, but this means that these pages will be the same:
www.mysite.com/blog/hello-world
www.mysite.com/blog/hello-worl
They both work, and bring up the same page. How (possibly using .htaccess?) can I get around this problem? :\
Many thanks
EDIT:
PHP -
if(isset($_GET['title'])) {
$blogtitle=mysql_real_escape_string($_GET['title']);
$title_two = strtolower(str_replace("-", " ", $blogtitle));
$title_two = strtolower(str_replace("?", "", $title_two));
$title_two = mysql_real_escape_string($title_two);
$postmatch = "select * from blog where title LIKE '%".$title_two."%' LIMIT 1;";
$postquery = mysql_query($postmatch) or die ("Could not match data because ".mysql_error());
$blogtitle=mysql_result($postquery,0,"title");
$title="$blogtitle";
Well you have the the URL : www.mysite.com/blog/hello-world WHERE hello world is the search string
I recommended you to store them into array like
$keyWrd = array();
$keyWrd = strtolower($_GET['keywd']); // MUST DO VALIDATION
$keyWrd = explode(" ",$keyWrd);
$TotalKeyVal = count($keyWrd);
if(!empty($keyWrd[0]))
{
$SrcQryStr = "SELECT id,title,body FROM tbl_name WHERE";
for($i=0;$i<$TotalKeyVal;$i++)
{
$SrcQryStr .= " title LIKE '%";
$SrcQryStr .= $keyWrd[$i];
$SrcQryStr .= "%'";
$SrcQryStr .= ' OR ';
$SrcQryStr .= " body LIKE '%";
$SrcQryStr .= $keyWrd[$i];
$SrcQryStr .= "%'";
if(($TotalKeyVal-1)!=$i) $SrcQryStr .= ' OR ';
}
$SrcQryStr .= " ORDER by created_date DESC";
Now you have the $SrcQryStr Query string You can make more condition on if(!empty($keyWrd[0]) && MORE HERE)
In here you can use implode or multiple implode instead of for loop.
Now why %.$keywd.%
Example :
STRING : Welcome to Stack Overflow!
Searched Keyword : ack
it will show match found because ack found on Stack WHILE %.$keywd.%
it will not show match found because there is no word which starts with ack WHILE $keywd.%
it will not show match found because there is no exact word ack WHILE $keywd
Can you provide a reason why you need to do it this way?
Do you require "hello-world" and "hello-world123" to match, but not "hello-worl" ?
Otherwise, I cannot think of any reason you would want to use a LIKE but not want to allow "hello-worl" to match.
Why not replace this:
$postmatch = "select * from blog where title LIKE '%".$title_two."%' LIMIT 1;";
...with this?
$postmatch = "select * from blog where title LIKE '$title_two' LIMIT 1;";
That way you're still searching regardless of capitalization, but not matching regardless of surrounding characters.