How to make SEO friendly URLs

Making Search Engine friendly URLs for your blog or website is so easy, This post will explain you Why to make SEO friendly URLs and how to make SEO Friendly urls using .htaccess or PHP code…

What are the SEO Friendly URLs ?
As we know SEO stands for Search Engine Optimization, Now let’s understand SEO friendly URLs… Basically we have common url in our website or blog e.g.”my%first%post” Such kind of URLs are not SEO friendly because as per Search Engine algorithm,

They only read keyword etc. and if your blog url content such a relevant keywords that people used in search e.g. These simple URL called SEO friendly URLs…

From an SEO point of view,  a website’s URL structure should be follow these points …

  • Straightforward: URLs with relevant keyword and URL should not be ugly that includes special characters and something like that user can not remember…
  • Meaningful: URL names should have keywords in them, So that it create some meaning of the text …

Benefits of SEO Friendly URLs :-

Friendly URLs improves your site search engines ranking. Before trying this you have to enable module at httpd.conf. It’s simple just few lines of PHP code converting title data to clean URL format.

How to make SEO Freindly URLs ?

There is many techniques to rewrite the URL(making SEO friendly URLs ) , but I can say here is the one of the best way to making URLs SEO Friendly using some PHP code..

Let’s try..

Step 1 :  Just create a database table to store page content in that..Sample database table  for blog that contain columns id, title, body and url…


Step 2 :  In this step let’s create a page blog-page.php

It contains some PHP code. Converting title text to friendly url format and storing into blog table…

//including db file
function string_limit_words($string, $word_limit)
$words = explode(' ', $string);
return implode(' ', array_slice($words, 0, $word_limit));

//Title to friendly URL conversion
$newtitle=string_limit_words($title, 6);

// First 6 words
$urltitle=preg_replace('/[^a-z0-9]/i',' ', $newtitle);
$newurltitle=str_replace(" ","-",$newtitle);
// Final URL

//Inserting values into my_blog table
mysql_query("insert into blog(title,body,url) values('$title','$body','$url')");
//HTML Part
<form method="post" action="">
<b>Title:</b><input type="text" name="title">
<b>Body:</b><textarea name="body"</textarea>
<input type="submit" value=" Publish "/>

Step 3 :   In this step let”s create a new file article.php that contains HTML and PHP code. We will fetch content from blog table and will display them on this page …

//Friendly URL 
if($_GET['url']) { $url=mysql_real_escape_string($_GET['url']); $url=$url.'.html'; 

$sql=mysql_query("select title,body from blog where url='$url'");
{ echo '404 Page.'; }

//HTML Part
if($count) { echo '<h1>$title</h1><div class="body">$body</div>'; }
{ echo '<h1>404 Page.</h1>'; }

Step 4:   In the final step .. you need to create a file and put the code given below into the .htaccess file and than upload it to your website root directory…

RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+).html$ article.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ article.php?url=$1

That’s it !!!

Leave a Reply

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

3 − two =