Create Search Engine friendly URL in PHP and htaccess

Image you have a Website which deals with news/updates on finance industry. You have admin panel where you used to post news/ image gallery on each category. Each category/post on your website has one unique id which is generated when you create any new category or post any news in that category.

When you post news under category ‘Investment’ which has category Id 3 in database and gave post title ‘Best long term investment options in India’ which has a post id 207 in database. Your post URL will contain those Ids so that it will recognize the post need to display to user.

This approach of creating URL has few issues.

  • Not human readable/friendly
  • Missing important searchable Keywords
  • It’s not Search Engine friendly

Search engines and users may have problems with complicated URLs. A clear, simple and descriptive URL will be more attraction-sicker to both Human and Search Engines.

Friendly URL
Search engine friendly or human-readable or clean URLs are URLs that make sense to both humans and search engines because they explain the subject of the Page/Post it’s pointing to.
Let’s see how we can create a Search Engine friendly URL using .htaccess and PHP. You need to first enable apache mod_rewrite module for this code to work.

Following PHP code will convert your parametric URL into Search Engine Friendly URL.

Calling create_final_url function will convert to

Make sure you add following htaccess rule in your .htaccess file.

About the Author

has written 69 posts.

I Love Coding, Analyzing, Designing and doing it the right way. I am obsessed about learn anything new daily and sharing what I have learn each Day. This Blog is journey of my Zeal, going through step by step to the mountain of desire to become prefect. Google Wanna Hire me ?

Copyright © 2020 All rights reserved.
Proudly powered by WordPress. Developed by 7Tech Solutions