عربي

What is Takhreej?

It is a very simple customizable PHP open source web addresses (URLs) manager and router, suitable for simple websites.

User Guide:

All you have to do is to download the source code, and save it in your web root. Takhreej supposes that your web pages are stored under the folder named pages which is stored under the web root directly (you can change it by modifying the line 77 in the source code), also, Takhreej supposes that you are using unified layout for all the pages (header & footer) which are stored under the folder named layout which is stored under the web root directly (you can change it or disable it by modifying or removing the lines 75 & 79 in the source code).
In case you used Takhreej as it is, your directory tree might look like this *:
root

├── index.php

├── layout
│   │
│   ├── header.php
│   └── footer.php

└── pages
    │
    ├── home.php
    ├── 404.php
    ├── about.php
    ├── contact.php
    │
    └── thread
        │
        ├── add.php
        ├── view.php
        └── index.php
Simply, if you request yoursite.com then the file home.php will be rendered, and if you request yoursite.com/about then the file about.php will be rendered, and if you request yoursite.com/thread/add then the file add.php will be rendered, and so on, and it worth to mention that the two layouts files (header.php & footer.php) will be rendered with every page unless you disabled or modified them.
* What is in italic is example

Important Note:

Your .htaccess file should have the following lines:
1RewriteEngine On
2RewriteCond %{REQUEST_FILENAME} !-f
3RewriteCond %{REQUEST_FILENAME} !-d
4RewriteRule ^/?(.*) index.php [L]

Download & Development:

Takhreej is a seed for an open source web addresses (URLs) manager and router, it will be developed later on, you can participate in Takhreej's development or downloading it on GitHub.
Or you can download it here directly.

Source Code:

<?php
 /**
 * Project:     Takhreej: Simple PHP Open Source Web Addresses (URLs) Manager
 * File:        index.php
 *
 * Copyright (c) 2014, Mohammad Anini
 * The project is licensed under Waqf Public License 2.0 <http://ojuba.org/wiki/waqf-2.0/>
 *
 * @link http://takhreej.anini.me/
 * @copyright 2014 Anini
 * @author Mohammad Anini <mohd.anini@gmail.com>
 * @version 1.0.0 (Feb 3, 2014)
 * @package Takhreej
 */
/**
 * Important notes:
 * 
 * 1. The .htacess file should have the following lines:
 * 
 *    RewriteEngine On
 *    RewriteCond %{REQUEST_FILENAME} !-f
 *    RewriteCond %{REQUEST_FILENAME} !-d
 *    RewriteRule ^/?(.*) index.php [L]
 *
 * 2. All the pages should be saved as .php files
 *
 * 3. This URL Manager supposed that all the pages are stored under "pages" directory which
 *    is under the root directory (you can change it!).
 *
 * 4. The main layout (footer & header) should be stored under "layouts" directory which is
 *    under the root directory (you can change it!).
 */
if (!empty($_SERVER['REQUEST_URI']))
{
    $root = dirname(__FILE__);
    // The requested URI
    $file_name = $_SERVER['REQUEST_URI'];
    // The actual index page (home page) must have another name or another location to avoid
    // recursion, we supposed that it's in the pages directory with "home.php" name (you can
    // change it!).
    if ($file_name == '/index.php' || $file_name == '/')
    {
        $file_name = 'home';
    }
    
    // Change the following to set title and description for every page in your site, and you
    // can use these variables in the header if you are using layout (header & footer),
    // otherwise just remove or comment out the following switch satement.
    switch ($file_name) {
        case 'banana':
            $title = 'I love banana!';
            $description = 'I love banana!';
            break;
        default:
            // Used for the home page
            $title = 'My lovely site!';
            $description = 'You will fall in love with my site!';
            break;
    }
    // If the requested file is not exists, the 404 page (which must be in the "pages"
    // directory) will be rendered.
    if (!file_exists($root . '/pages/' . $file_name . '.php'))
    {
        header('HTTP/1.0 404 Not Found');
        $file_name = '404';
    }
    // Rendering the header
    require_once $root . '/layout/header.php';
    // Rendering the requested page
    require_once $root . '/pages/' . $file_name . '.php';
    // Rendering the footer
    require_once $root . '/layout/footer.php';
    exit;
}