create your own

Take Advantage of Friendly URL's With The Helix PHP Framework

66
rate or flag this page

By johnathanhebert


What Are Friendly URL's?

Friendly URL's are website addresses that are clear, concise, and don't have lots of "junk" in them. A good friendly URL might look something like...

http://www.example.com/blog/2009/january/how-to-bake-a-cake

It is pretty obvious just from looking at this URL that it takes you to a blog entry written in January of 2009 and it is about how to bake a cake. The same URL can be written in a very unfriendly way...

http://www.example.com?cmsId=1843&page=__show&m=1&y=2009&topic=x-231&blogId=773

Looking at that URL... it is very unclear what it is about, and it's just plain ugly. Yes, it may show you the same page, but it will hurt your ranking on search engines and your SEO in general.

Setting Up Friendly URL's On Your Site

One way to set up friendly URL's on your site is to make a bunch of directories under your web root with nice organized names.  While this is entirely possible, it is not a great choice because the actually blog entry is most likely stored in a database, so there would have to be a file in every directory that included a script to connect to the database and display the blog entry.

Using the Helix PHP Framework, you can use the friendly URL by simply creating one single page called "blog", and using the URL as a variable list, you can retrieve the blog entry from your database and display it to the user.

Let's break apart the example URL given above:

1) http://www.example.com/ is the website domain.  This is where your Helix PHP Framework is installed.

2) blog/ is the page name you created.  You can edit the code for this page in the "helix/sites/example/interface/pages/markup/blog.php" file where you installed the Helix PHP Framework.

3) 2009/january/how-to-bake-a-cake are the parameters passed to the PHP script in blog.php  -- These will show up in the global $params array where

$params[1] = "2009"

$params[2] = "january"

$params[3] = "how-to-bake-a-cake"

Look at the code below to see how you can retrieve the blog entry from the database and display it to the user using the information on the URL.

Display A Blog Entry Using Friendly URL's

$articles = article::get_objects(null,null,"title='{$params[3]}'");

if (count($articles)==1)
{
	$article = $articles[0];
	h1::open();
		echo $article->summary;
	h1::close();
	p::open();
		echo $article->data;
	p::close();
}
else
{
	error("This blog entry could not be found.  Please select another.");
	redirect("blog/{$params[1]}/{$params[2]}");
}

Print   —   Rate it:  up  down  flag this hub

Comments

RSS for comments on this Hub

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working