-
URLs with no IDs in Php
I have a piece of code and i'm trying to modify it to list the URLs more seo friendly.
Currently the URLs are displayed like this :
/view/3456/keyword.html , is posible to display the URLs as /view/keyword.html without the ID number ?
PHP Code:
<?
$sql = mysql_query("SELECT * FROM my_data WHERE published=1 ORDER BY id desc LIMIT 10");
while($row = mysql_fetch_array($sql))
{
$abcd= $row['name'];
$abcd = str_replace (" ", "-", $abcd);
if ($seo_on == 0)
{
$url = 'index.php?task=view&id='.$row['id'].'';
}
else
{
$url = 'view/'.$row['id'].'/'.$abcd.'.html';
}
echo ' <a href="'.$site_url.'/'.$url.'">'.$row['name'].'</a><br>';
}
?>
Or i need to modify something else to make it work because if i type www.domain/view/keyword.html i see page not found.
-
http://www.domain.com/index.php?task=view&id=2345
In htaccess:
PHP Code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)-(.*)\.html$ /index.php?task=$1&id=$2
result: http://www.domain.com/view-2345.html
Just noticed that you mean editing your given code:
Try this,
PHP Code:
<?
$sql = mysql_query("SELECT * FROM my_data WHERE published=1 ORDER BY id desc LIMIT 10");
while($row = mysql_fetch_array($sql))
{
$abcd= $row['name'];
$abcd = str_replace (" ", "-", $abcd);
if ($seo_on == 0)
{
$url = 'index.php?task=view&id='.$row['id'].'';
}
else
{
$url = 'view/'.$abcd.'.html';
}
echo ' <a href="'.$site_url.'/'.$url.'">'.$row['name'].'</a><br>';
}
?>
-
The page is pointing to the main page but is a good sign anyway, better than not found.