如何使用 SLUG php mysql 从 url 检索数据

问题描述

我只想在 href 中发送博客的 slug。代码 post_url = 该博客标题的 slug

<h3><a href="<?= $base_url ?>blog/<?=$rowposts['post_url']?>">Read</a></h3>

网址是这样的 - http://localhost/Office/VTPL/Varneli%20HOME_CMS/vareli-home/blog/this-is-my-blog

enter image description here

这是 .htaccess 文件截图。请检查所选行

enter image description here

请帮帮我...我该怎么做...

解决方法

用这个替换你的 .htaccess 行

RewriteRule ^blog/([A-Za-z0-9_-]+)/?$    blog/blog-details.php?post=$1     [L,QSA]

获取网址,PHP代码

$full_url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";