Welcome to Techno Smarter QA, Questions, Answers Community
Welcome to Techno Smarter Q&A, where you can ask questions and receive answers from other members of the community. Ask the Technical & Programming related questions that you want. Guests Posting are allowed.
+2 votes
I want to make SEO friendly URL in PHP I am trying to many days but unable to solve this error. When I click on news then slug change but post data not change.
in PHP by (210 points) 8

2 Answers

+2 votes

You can create SEO friendly URL with PHP and MYSQL database. If you are not getting URLs related data on the page then check your condition.GET blog posts slug and fetch data by post slug. Like this-

 $stmt = $db->prepare('SELECT articleId,articleDescrip, articleSlug ,articleTitle, articleContent, articleDate FROM techno_blog WHERE articleSlug = :articleSlug');
$stmt->execute(array(':articleSlug' => $_GET['id']));

You can check the complete tutorial here


by (6.7k points) 7 27 60
edited by
Ok thanks for reply
+1 vote

SEO friendly URLs help in the ranking of blog and website pages. SEO friendly URL contains the page content keywords. We can customize the URL according to our needs. Yes, you can create SEO friendly URL with PHP and MYSQL database. In PHP, we convert the page title into SLUG.SLUG is another format that is converted by PHP functions.   

Make SEO friendly URL with PHP and MYSQL database-

Title - How to make SEO friendly URL 

SLUG of title- how-to-make-seo-friendly-url 

Slug contains a minus sign between words.  

We create a slug() function in PHP using PHP builts functions. The slug() function is used to convert the title to slug (As we discussed above).  


function slug($text){ 

  // replace non letter or digits by -

  $text = preg_replace('~[^\\pL\d]+~u', '-', $text);

  // trim

  $text = trim($text, '-');

  // transliterate

  $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

  // lowercase

  $text = strtolower($text);

  // remove unwanted characters

  $text = preg_replace('~[^-\w]+~', '', $text);

  if (empty($text))


    return 'n-a';


  return $text;



The slug() function is created with many built functions of PHP. 

If you want to create an SEO friendly URL in PHP then you have to create another column in the table. 

Like - titleSlug 

The titleSlug column will help you insert, update the slug. 

First of all, use convert the website page title or blog post title to slug using slug function. 

Like - 


Use titleSlug with the query and insert into the database table 

The page title will be converted into a slug .  

In this way, you can make SEO friendly URL in PHP with an MYSQL database. 

Now, you can fetch and display unique data using slug. 

You have an issue with the query. Insert the unique data in every row. Do not add the same data in every row. 

Create a query like this - 

SELECT pageTitle,pageContent from table_name WHERE titleSlug=:titleSlug 

Make sure to GET unique titleSlug on the show page. 

It will help you fetch the unique data on-page. 

This tutorial is available here - 

Create SEO friendly URL in PHP with MYSQL database

for better understanding try to learn from the beginning 

How to create blog using PHP and MYSQL database 

These are enough to learn and create the SEO friendly URL in PHP. 

by (8.9k points) 8 22 61