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 URLs 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).
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
$text = trim($text, '-');
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $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 the slug function.
Use titleSlug with the query and insert it into the database table
The page title will be converted into a slug.
In this way, you can make SEO-friendly URLs in PHP with an MYSQL database.
Now, you can fetch and display unique data using a 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 a 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.