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
//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.
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
Post a Comment