Monday 14 April 2014

Creating and understanding SEO-Friendly URL'S Part 2

First guys we will look how a slug url look like 

http://www.example.com/This-is-a-seo-friendly-url

This is a  demo and this is what we are looking to achieve

So lets's the hacking begin.......

First we will create  a function which will handle the preparation of a slug url

<?php
    function generate_slug($slug)
  {
echo $text = "TTutorial to    show you how to create a ----- safe slug url v`v`k``` generator";
        echo "<br/>";
 ///// first remove everyting  other than spaces,hypens,number,letters and make the string to lowercase 
        echo $remove_slug1 = preg_replace("/[^\-\s\pN\pL]+/u", " ", mb_strtolower($text,'UTF-8'));

   echo "<br/>";
    /////  remove duplicate hypens and spaces//////
   echo $remove_slug2 = preg_replace("/[\-\s]+/", "-", $remove_slug1);
   echo "<br/>";
   echo $remove_slug3  = trim($remove_slug2,"-");
}
?>


Creating and understanding SEO-Friendly URLS Part 1

Clean URLs, RESTful URLs, user-friendly URLs or SEO-friendly URLs are purely structural URLs that do not contain a query string [e.g., 
action=delete&id=91] and instead contain only the path of the resource (after the scheme [e.g., http] and the authority [e.g., example.org]). This is often done for aesthetic, usability, or search engine optimization (SEO) purposes. Other reasons for designing a clean URL structure for a website or web service include ensuring that individual web resources remain under the same URL for years, which makes the World Wide Web a more stable and useful system, and to make them memorable, logical, easy to type, human-centric, and long-lived


Examples of "unclean" versus "clean" URLs follow:
Unclean URLClean URL
http://example.com/index.php?page=foohttp://example.com/foo
http://example.com/index.php?page=consulting/marketinghttp://example.com/consulting/marketing
http://example.com/products?category=2&pid=25http://example.com/products/2/25
http://example.com/cgi-bin/feed.cgi?feed=news&frm=rsshttp://example.com/news.rss
http://example.com/services/index.jsp?category=legal&id=patentshttp://example.com/services/legal/patents
http://example.com/kb/index.php?cat=8&id=41http://example.com/kb/8/41
http://example.com/index.php?mod=profiles&id=193http://example.com/profiles/193
What is Slug ?
A slug is the part of a URL which identifies a page using human-readable keywords. It is usually the end part of the URL, which can be interpreted as the name of the resource, similar to the basename in a filename or the title of a page. The name is based on the use of the word slug in the news media to indicate a short name given to an article for internal use. For example, in

http://www.example.com/services/legal/medical-patents
Hope you guys have understood something about SEO Friendly URls
In the next part we will create a slug function to create a  seo friendly URL.