skip to Main Content

I am developing a website in core php with custom cms. I am facing problem while making the blog url’s seo friendly.

My Url is of this type and I want the url like
If I fix it through htaccess file, that will be static because i want a single function which works for future blog posts as well.
So Please Help me to solve this issue.



  1. Make the specific blog title a $_GET value with htaccess

    RewriteRule    ^blog/([A-Za-z0-9-]+)/?$    /blogs.php?blog=$1    [NC,L]

    then you can print the blogs out from the blog` id or title

    Once that is set up you need to get the $_GET data from the blog table of the database in your blogpost.php script like so:

    $sql ="SELECT * FROM blog_table WHERE title = ".$_GET['blog']." LIMIT 1";
    $blog = mysqli_fetch_array(mysqli_query($sql));
    echo '<h1>'.$blog['title'].'</h1>';
    echo '<p>'.$blog['content'].'</p>';

    obviously security needs to be thought about and prepared statements would be better.

    Login or Signup to reply.
  2. You could try:-

    RewriteEngine On
    RewriteBase /
    RewriteRule ^blogpost.php/(.+)(/?)$ /blogpost.php/?post_slug=$1 [NC,L]
    # or slightly nicer would be to remove the `.php` thus:-
    RewriteRule ^blogpost/(.+)(/?)$ /blogpost.php/?post_slug=$1 [NC,L]
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top