Readable URLs

The Jadu readable URLs functionality provides a mechanism to create semantic, human readable URLs. This is achieved by making use of the Apache rewrite module (mod_rewrite).

Rewrite rules have been created for all standard Jadu front-end scripts and these are stored in jadu/htaccess_readable. When Continuum CMS is installed this file is copied to the public_html/.htaccess. The `.htaccess file is also used to store rewrite rules created using the Friendly URL module.

Each time a friendly URL is created, updated or deleted the htaccess_readable file is copied from the jadu directory to public_html/.htaccess and all friendly URLs are added to the file.

By default every script is available by making a request based on the path to the file from the document root, for example http://<domain>/site/scripts/news_article.php?id=12.

The rewrite rules specify patterns that map onto these default scripts. For example, the rewrite rule below means that a request to /rss/news` will be rewritten as a request to the actual script/site/scripts/rss.php`

RewriteRule ^rss/news/?$ /site/scripts/rss.php [NC,L]

Rewrite rules can contain parameters for dynamic requests as follows:

RewriteRule ^info/([0-9]+)/[^/]*/?$ site/scripts/documents.php?categoryID=$1 [NC,L]

This rewrite rule takes the first matched bracketed expression ([0-9]+) and uses it as the id of the category passed to the documents.php script. The part of the expression after the second / - [^/]* - allows any characters to be placed before the next /, effectively allowing a more readable URL.

All web site links are are generated using functions in the file utilities/JaduReadableURLs.php. The name of each function typically takes the form buildXURL(...), where X is used to identify the URL being created. For example:

/**
 * This function returns an A to Z URL to the az_index.php script.
 * @param string $startsWith The A to Z letter
 * @return string
 */
function buildAToZIndexURL($startsWith)
{
    if (READABLE_URLS_ENABLED) {
        return "/a_to_z/$startsWith";
    }

    return "/site/scripts/az_index." . GetScriptFileExtension() . "? startsWith=$startsWith";
}

The intention of this function is to create a URL used for linking to the A-Z script, allowing a letter to be made part of the URL so that the script can determine what A-Z entries to display.

It is possible for readable URLs to be enabled and disabled in the Jadu Control Center. It is therefore necessary to determine whether readable URLs is enabled or not. This can be done, as can be seen in the example, by checking the READABLE_URLS_ENABLED constant. This will be set to 0 if readable URLs are disabled and 1 if they are enabled. Once it has been determined whether readable URLs is enabled or not the correct URL can be returned – either using the readable format set in htaccess_readable or the standard path to the script based on its location relative to the document root.

Custom readable URLs can be placed in the file jadu/custom/CustomReadableURLs.php. This file, if it exists, is automatically included when utilities/JaduReadableURLs.php is included.

results matching ""

    No results matching ""