What is a Seo Friendly Url ?
A search-engine-optimized URL is one that has been constructed to improve a webpage’s ranking and visibility on search engines by providing clear information while being friendly to users. It tends to be short, descriptive, readable, consisting of relevant keywords that adequately reflect the content of that page in order to make it pertinent. Simply put, SEO-friendly URLs are clean and logical and do the job easily when compared to complicated URLs dealt among varying character types and parameters. For example, this URL
https://example.com/blog/php-best-practices-2025
is way more SEO-friendly than this URL.
https://example.com/index.php?category_id=123&post_id=4567.
Some of the principal characteristics of an SEO-friendly URL are separating words with hyphens, avoiding stop words, shorter is more optimal, and having no special characters or limitlessly added parameters. This, in turn, helps search engines understand what the page is about, thus making it easier for the user to remember and share that link. Furthermore, SEO-friendly URLs are faster to come up with for browsing through search results since they convey to users what they can expect on that page before they click on it. Thus, in its simplest sense, you can improve your web address’s search engine ranking through SEO, increase organic visits, and give your business a more professional and trustworthy tint on the web.
A URL that only contains random identifiers is less helpful for users
Google Search Engine Optimization (SEO) Starter Guide
so in these article we will create a php function to sanitize and clean urls to output a seo friendly url
PHP
<?php
// Create a seo friendly urls
function SEO($input){
//SEO - friendly URL String Converter
$input = str_replace(" ", " ", $input);
$input = str_replace(array("'", "-"), "", $input); //remove single quote and dash
$input = mb_convert_case($input, MB_CASE_LOWER, "UTF-8"); //convert to lowercase
$input = preg_replace("#[^a-zA-Z]+#", "-", $input); //replace everything non an with dashes
$input = preg_replace("#(-){2,}#", "$1", $input); //replace multiple dashes with one
$input = trim($input, "-"); //trim dashes from beginning and end of string if any
return $input;
}
//usage
//echo seo('text');
//example
$text = 'ConVeRt @Me## IntO** Seo&& FriendlY+Url';
echo 'Text : '.$text;
echo '<br>';
echo 'Result : '.seo($text);
Result
