Skip to main content

HOW TO CREATE WEBSITES DRIVEN BY SEO FRIENDLY URLS WITH OUT USING HTACCESS

CREATING WEBSITES DRIVEN BY SEO FRIENDLY URLS WITH OUT USING HTACCESS

In this article I will explain how we can create websites which are driven by seo friendly urls with out using htaccess.

To read about SEO and HTaccess please read how to create SEO friendly url driven websites using HTaccess rewrite function

When we use HTACCESS for SEO friendly redirections, we use mod_rewrite module of apache. We can create seo friendly url driven site with out using the htaccess mod_rewrite module functions.

I will try to explain it very simple:

take this url path as example "http://www.myphpwebsite.com/"

for this you need a index file in the root folder
like this : http://www.myphpwebsite.com/index.php

The content for this page will be populated based on a parameter "content"

like this : http://www.myphpwebsite.com/index.php?content=home

so content of this page changes as the parameter value changes, the contents may be driven from database or include files

sample calls
http://www.myphpwebsite.com/index.php?content=home
http://www.myphpwebsite.com/index.php?content=contact-us
http://www.myphpwebsite.com/index.php?content=vacancies


so if you can fetching contents from the DB, you will be fetching contents from the contant table based on the supplied parameters
OR
You will be showing contents by including a file which is identified by the  supplied parameters.

for example when you call
http://www.myphpwebsite.com/index.php?content=home

you will be including a file like "home.php" into the main page ie, "index.php"


if( is_file("includes/home.php") )
include_once("includes/home.php");
 else
include_once("includes/page-not-found.php");
?>


Dont think I had diverted from the point....:)  I am coming to it..

Actuall trick starts from here

I am explaining the stuffs based on an assumption that out Main page "index.php" is using one parameter and the way it uses the param plays the trick of feeling like SEO friendly Urls.

You have to set the directory Index of your root folder to index.php.

You can refer index page like
http://www.myphpwebsite.com/index.php?content=home  
and also like
http://www.myphpwebsite.com/?content=home

I am using the second way for adding the trick ie
http://www.myphpwebsite.com/?content=home

when we access this parameter through Global Variable  as $_GET['content']

echo($_GET['content']);   will display  "home"

For applying trick we can use parameter value as the Parameter

like

http://www.myphpwebsite.com/?home

so Let see how it can be accessed in the main page  "index.php"

For proper working of the following code, the file name of the included file and the supplied parameter key should be same.

like , if you call http://www.myphpwebsite.com/?contact-me
then, there should be a file named "contact-me.php" in the "includes" folder and the file location will be like:
http://www.myphpwebsite.com/includes/contact-me.php



save the following code as index.php
in the code below i assume the  contents in the index.php are  included from "includes" folder at location
http://www.myphpwebsite.com/includes/

//code starts here   

<?php

// php section of the file

$my_title="Home : My Php Website";
$my_page="includes/home.php";

if( isset($_GET) && trim( key($_GET) )!="" ){
$my_page=strtolower(trim( key($_GET) )).".php";

if( is_file("includes/".$page) ){
$include_page = "includes/".$my_page;
$my_title=ucfirst(str_replace("-"," ",trim(key($_GET)) ));
}
else $include_page="includes/page-not-found.php";
}

?>

<!-- Html section of the file-->
<html>
<head>
<title><?php echo($my_title);?></title>
</head>
<body>
<?php
include_once($include_page);
?>
</body>
</html>

//code ends here 

Its Done. Now take your page http://www.myphpwebsite.com/

you can call other pages like

http://www.myphpwebsite.com/?home
http://www.myphpwebsite.com/?contact-us
http://www.myphpwebsite.com/?vacancies



Here I had used only single parameter to define the pages, you can modify the script and make it as multi param driven.



Comments

Popular posts from this blog

Sachin Tendulkar's emotional farewell Speech at Wankhede Stadium, Mumbai - Full Text and Video

Full Text and Video of Sachin Tendulkar's emotional farewell Speech on Nov 16, 2014 On November 16, 2013 - Sachin Ramesh Tendulkar played his last international cricket match against West-Indies at the at Wankhede Stadium, Mumbai. After the match he gave an emotional farewell speech. No one would be able forget the speech. The eyes of the gathered people were tearfull. Through out the speech Sachin thanked each and everyone who supported and encouraged him to build up his glorius career which spanned 24 years.

How to remove backlinks to your website from low quality websites and how to Disavow websites?

Some webmasters may find their website's traffic dropped significantly after a particular day. The day before the traffic drop, might have received lots of visitors, but after that the web traffic dropped to less than 50%. Periodically Google releases some search algorithms which tracks low quality sites and penalise pages so that they may not appear in top positions of the search results there after and this will lead to low traffic to that website.

PHP script to list files in a given directory using opendir, readdir and glob functions

PHP script to list files in a given directory The below given script goes through a given directory and list the name of the files in the order as it is stored in the file system. The first script uses a directory handler to operate on a given directory. It opens the handler, reads file entries one by one by looping through the directory (during this step you can process the file ) and finally close the handler


Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »
Member
Search This Blog