Search code examples
php.htaccessurl-rewritingslug

How to retreive data from url using SLUG php mysql


I just want to send slug of the blog in href. Code post_url = slug of that blog title

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

Url will be this - http://localhost/Office/VTPL/Varneli%20HOME_CMS/vareli-home/blog/this-is-my-blog

enter image description here

Here is the .htaccess file screenshot. Please check the selected line

enter image description here

Please help me out... How will I do that...


Solution

  • Replace your .htaccess line with this

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

    To get URL, PHP code

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