Creating a Clean & SEO Friendly Url with PHP

You might have read about Search Engine Friendly URLs which are considered a backbone of SEO. A website’s URL Structure should be Clean and SEO Friendly and must not include Special Characters, because URLs with Special Characters are difficult to be remembered by a user. In this post I will discuss about some methods by which you can make a User Friendly & Search Engine Friendly URLs in your website.

Creating a Clean & SEO Friendly Url with PHP

The first and most important thing to keep in mind is, don’t create Urls with Special Characters like & ! @ # $ % ^ & * ( ). Search Engines will not encourage URLs having this kind of structure. Instead you should use URLs which contains only Alphabets and Numbers.

Secondly, you should use dashes as separators instead of spaces or underscores, as spaces are converted to %20 sign when indexed by Search Engines. Underscores are also not considered a best option as a separator because a text with underscores is considered a regular expression and they do not separate the words instead they make it one complete word.

Now let me tell you about How to Create an SEO Friendly and Clean Url with PHP. See the below code:

Making an SEO Friendly Url using PHP:

Following code will let you convert a simple text line into an SEO ready text for using in your url. Here we are using PHP language for removing unwanted special characters and repeated spaces and/or plus signs from our url:

Above is a PHP Function which will receive the text input from you and will return cleaned output which can further be used in your Url. Here is the usage of this function:

Usage of Clean Url Function:

This function is very simple to use. You just need to pass one parameter and it will process the whole string/text and will return output. You can save the output in a variable and use it where ever you want. See the example usage of this function below:

Now $clean_text variable contains our cleaned text. We can now use it to make our url like this:

 Complete Code:

Here i will show you complete usage of this function and creation of our URL:

Feel free to download this script from here and use it anywhere in your code/projects.

Creating A Clean & SEO Friendly Url With PHP
Creating A Clean & SEO Friendly Url With PHP
Creating a Clean & SEO Friendly Url with PHP.zip
877.0 B
31 Downloads
Details

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

scroll to top