Latest Websites

Die Kak Pot

Saffa Kakhuis, my alter ego, decided to start playlisting songs from SaffaTunes in the form of a podcast, to boost...>>read more.

SaffaTunes.com

SaffaTunes.com is my own hobby site, I have always been a huge fan of South African music, after having moved to London I was finding it difficult to stay up to date...>>read more.

My Blog

Web Design Strip

Comparison WHMCS Addon

I have been developing a few websites for the past two months, most notably would have to be WHM.....
read more.

Thick as Thieves

The kids messed the kitchen up this morning by flinging butter against the walls, when I asked them the first time who did it, they pointed to.....
read more.

Tutorials Index

  1. 2

  2. Smarty Functions

    1. This URL Smarty Function
  3. Smarty Pagination Plugin

    1. Pagination Class
    2. Smarty Pager Function
  4. Build a scalable website/weblog/cms

    1. Getting Started
    2. Build the Foundations
    3. Dynamic SEO Friendly URL
    4. PHP Helper Classes

Tutorials Intro

These tutorials reflect personal projects while practicing of new tools, ideas, techniques and technologies. They can not be used on their own as a final solution for any website.

I will be using xHTML, CSS and PHP in most of the tutorials so a basic understanding of each will be ideal but not a requirement if you work each tutorial from the beginning. I will also be making use of the jQuery javascript API for effects, AJAX and loads more.

My personal favourite has got to be the versatile and highly scalable php Smarty Template Engine, so almost everything I build uses it. I'm not on my own in working with and trusting the smarty template engine, there are loads of large names out there using it, Jamroom, XOOPS CMS, Movable Type, WHMCS, Serendipity, CMS Drupal to name a few, go to Smarty's Resources page for more.


Dynamic SEO Friendly URL


Tutorial:  Build a scalable website/weblog/cms

Skills:     xHTML, php, smarty, .htaccess

Goal:      Create a SEO friendly website.

Last time I introduced our php class object called SmartStart, in my next tutorial I would like to show you how our index.php file is pretty much going to host every webpage on the site, take a quick look at the .htaccess file to immediatly start redirecting any non www. calls to www.yourdomain.com and extending on having index.php look more user friendly.

/index.php
<?php
//include our Smarty class file
require 'includes/Smarty/Smarty.class.php';
require 'lib/SmartStart.class.php';
//See if $_GET['t'] isset, if it is, assign it's value to our new variable named $template
if(isset($_GET['t'])){
$template = $_GET['t'];
}else{
//If it isn't set, let's pass through our index/default template
$template = 'index';
}
//create a new SmartStart object and tell it what template to fetch
$smarty = new SmartStart($template);
//assign a value to a variable for use in our template
//$smarty->assign('var','value');
$smarty->assign('title','Web Master Tutorials');
$smarty->assign('content','This is the the content that will be assigned to the $content variable in the .tpl file called with $smarty->display()');
//Now we tell the object to display the page
$smarty->display();
?>

With the new /index.php you are able to call any template you create in your /templates/ folder, so if I call /index.php?t=My_Template , you'll be viewing /templates/My_Template.tpl in the browser window.

Next I create a .htaccess file in the root folder, I'm assuming one doesn't exist, if one does, make a copy of it, before editing it..

/.htaccess
#Tell apache to switch on Follow Symbolic Links
Options +FollowSymLinks

#Switch the rewrite engine on
RewriteEngine On

#Set a condition of, if a server request comes in for our domain without an appending www.
RewriteCond %{HTTP_HOST} !^www\.
#Rewrite the request and set a permanent(301) redirect, this step has no bearing on the website other than a search engine optimisation technique
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

#Set the base for further rewrites
RewriteBase /

#If we come in blank, load index.php
RewriteRule ^$ index.php [L]

#If we are linking to a script, css or image document, allow it and pass allong the request.
RewriteRule ^images/(.*?)$ images/$1 [L]
RewriteRule ^css/(.*?)$ css/$1 [L]
RewriteRule ^scripts/(.*?)$ scripts/$1 [L]

#This is the magic part, read any request to your site and pass the variables along to the index.php as get variables
RewriteRule ^(.*?)/(.*?)$ /index.php?t=$1$2 [NC]

Now we have the ability to create some friendly url's and all get passed through our /index.php file. Open your browser, www.yourdomain/My_Template/ to test it out.