I'm working with get and retrieving by id, I tried to use the title but unfortunately it does not work, so I adapted the url to have the id and title, so:
/postagem.php?id=69&post-para-front-end
I was trying to do it by .htaccess but it does not work at all, I would like to know a way to change this current url and just leave the title like this:
/post-para-front-end
I'm using usbwebserver, I do not know if that's the reason. follows the schedule.
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^contato/?$ contato.php [NC,L]
RewriteRule ^blog/?$ blog.php [NC,L]
RewriteRule ^sobremim/?$ sobremim.php [NC,L]
RewriteRule ^inicio/?$ index.php [NC,L]
RewriteRule ^$1/(.*)$ /posts.php?id=$2&slug=$1 [NC,L]
</IfModule>
Link on the page that calls the post
<a href="postagem.php?id=<?php echo $dados['id'] ?>&<?php echo slug($dados['titulo']) ?>"></a>
Slug function
<?php
function slug($str)
{
$str = strtolower(trim($str));
$str = preg_replace('/[^a-z0-9-]/', '-', $str);
$str = preg_replace('/-+/', "-", $str);
return $str;
}
?>