I am presently focusing on just a little web site project. I made the decision to make use of Apache (no clue of version), PHP (5.1.7, version enforced by my company) and Dwoo (templating) for this function.

I am presently missing a pleasant method to route Web addresses to my templates. I am aware you will find many frameworks carrying this out type of factor. I am just wondering if there is a nice method to do it without. :)

I have setup my project the following:

  • src/dwoo - Dwoo files
  • index.php - This will handle routing. Presently it simply renders the leading page from the site utilizing a template.
  • templates - Templates that represent actual pages.

There's minimal quantity of business logic (no real model). It's all regulated just pretty static pages. Using templates makes maintenance work simpler (inheritance ie.).

Any idea how to setup routing within this situation? I suppose ideally each given URL should route via index.php that then in some way decides which template to render (ie. /category/pagename would map to templates/category/pagename.tpl).

Use mod_rewrite to route everything to some single index.php file. Then look into the variable in $_SERVER['REQUEST_URI'] in this particular file to dispatch towards the needed handler.

This configuration will enable mod_rewrite, whether it's installed:

DirectorySlash Off
Options FollowSymLinks Indexes
DirectoryIndex index.php

RewriteEngine on

RewriteCond %{REQUEST_FILENAME}  -d
RewriteRule  ^.*$  -  [L]

RewriteCond %{REQUEST_FILENAME}  -f
RewriteRule  ^.*$  -  [L]

RewriteRule ^.*$    index.php [L]

You might like to use PEAR's Net_URL_Mapper.