PHP – Create SEO Friendly Slug URL

By on April 14th, 2019

5min Read

 blog image

Slug is the SEO friendly format of any text string. A slug is a text string contains alpha-numeric characters only, separated by “-“. Slugs play a significant role in web development because it’s easy to read, clean looking and SEO friendly. Search engines love clean slugs.

While working on a project I faced a requirement where slugs need to be created using the website links. So I added some extra lines of code in my existing create_slug() method and created a new function which is capable even to convert website URL’s into clean slug’s. This function will also add a “.html” extension at the end of the slug. Besides just making slugs from a string, this method is developed by keeping in mind to create slugs from website URL. The script will automatically remove the query string and will preserve the “/“, and “.” to convert them later into “–“.


Besides “.html” we can create our own extension.

 

Share on

More blog posts for you

Let's Increase Your Sales.

Talk with one of our certified web development professionals about how to get online.

    newsletter Join 5,000+ businesses smashing revenue goals with our weekly newsletters.