#1. -=== Intro ===-
In Cotonti we decided to add a easy system for re-writing URLs without the need for core hacking. This allows admins to easily design URLs in any fashion they want. This guide was written for 0.0.6 and greater, there are some things that might not be in older versions that appear in this guide.
The first 0.0.6 beta does not include a couple of the tweaks needed for this
#2. -=== Basic Setup ===-
- You need to create a .htaccess file if you don't already have one. This should be uploaded to your root web folder (the place with all your index/page/list/etc .php files. If you don't want to manually create rules this needs to be CHMOD 777. For this guide you will be manually creating your URLS. However the URL Rewerite does offer basic rules creation.
- You need to make sure that datas/urltrans.dat
is CHMOD 777
#3. -=== Basic URLs Tool Details ===-
This portion will detail the basics of the URLs page, and of what each option does.
First off to access the URL modifications tool goto
Admin >
Other >
URL or go straight to
admin.php?m=urls
- New Rule - This adds a new rule to the above list
- Area - This is the area the rule is for, it corresponds to "*".php
- Parameters - This is the URL you want to match for(modify)
- Format - This is what the URL will be formated into
- Delete - This well.... Deletes the Rule :)
- Overwrite .htaccess? - This will when checked, save the basic generated rules straight to .htaccess Not recommended if you are manually creating them
- Changing Order(Hidden) - To change the order of a rule simply click on a row(rule) and drag it into the position you want.Please note this requires javascript enabled
- Save - Saves any changes made :)
#4. -=== Basic URLs Modifcation & Details ===-
Most of this information i'm about to provide is listed in the
Help at the bottom of the URL page, but I will try to explain it in more detail.
The first thing to note is that don't include area.php or ? you just start with something=something
Parameters - This is the URL your trying to match
- * - This may be used to match against any url for a area or may be used to match anything for a variable
- Example 1: * - This will cause it to be called for all URLs
- Example 2: id=* - This will cause it to match if id is in the url and is not restricted by any value it has.
- | - This may be used to match against a specific value for a variable
- Example 1: id=1|2|3|15 - This will cause it to match any URL that contains ID but has the value of 1,2,3, or 15 no others will be matched
Format - This is what your creating the output of the URL to look like
- {$_area} - This may be used to output the Area which the url is for
- Example 1: {$_area}.html
- {$_host} - This may be used to output the Hostname (domain) from your $cfg['mainurl']
- Example 1: http://{$_host}/
- {$_rhost} - This may be used to output the Hostname (domain) from the current HTTP request (the URL they accessed the site with)
- Example 1: http://{$_rhost}/
- {$_path} - This may be used to output the server path to your site(if your site is in root its / or else its the path inside to the site)
- Example 1: {$_path}/something.html
- {$variables} - This may output the contents of any variable into the url
- Example 1: {$al}.html
- Example 2: {$id}.html
- {!$variables} - This can be used to unset variables that are in the url you do not want, if you do not do this they will be tagged onto the end with ? . The postion of this does not matter, but it would be recommended for visual sake to place it at the end
- Example 1: users/{$u}{!$m}{!$id}
- {callback_function()} - This is used for advanced URL manipulation, which allows you to edit the URL via a function. You can combine it with the above, but it would be recommended to do everything you need or want in the function.
- Example 1: {my_url_callback()}
#5. -=== Basic URLs Tool Examples ===-
These are some basic examples you can use that will actually work!
Pages
Page by ID
Page by Alias
Users
Users (to go along with this set it should be below the other users rules)
Users * by id
- Area: - users
- Parameters: - m=*
- Format: - {$_area}/{$m}/{$id}{!$u}
- Output Example: - users/details/1
- .htaccess Example: -
RewriteRule ^users/([a-z]+)/$ users.php?m=$1 [QSA,NC,NE,L]
RewriteRule ^users/([a-z]+)/([0-9]+)$ users.php?m=$1&id=$2 [QSA,NC,NE,L]
Users * by Username
- Area: - users
- Parameters: - m=*
- Format: - {$_area}/{$m}/{$u}{!$id}
- Output Example: - users/details/Kilandor
- .htaccess Example: -
RewriteRule ^users/([a-z]+)/$ users.php?m=$1 [QSA,NC,NE,L]
RewriteRule ^users/([a-z]+)/([^?]+)$ users.php?m=$1&u=$2 [QSA,NC,NE,L]
#6. -=== Advanced URLs Tool Examples ===-
This will show you how to use callbacks and is considered advanced, due to you have to manually create any htaccess rules, as well as creating PHP functions.
First off if your going to use callbacks you will have to include them, this may be done very easily.
- Create a file in system/ named functions.custom.php
- The first code snippet in this file should be
if (!defined('SED_CODE')) { die('Wrong URL.'); }
- Open your datas/config.php find $cfg['customfuncs'] = FALSE; and set it to true
This will cause the functions.custom.php to be included in functions.php, without any need for modifications.
This will explain the basics variables / information
- &$args - This contains all the variables of the URL
- Example 1: $args['id']
- &$spec - This contains a few special things that was listed above in the basic section, _area, _host, _rhost, and _path
- Example 1: $spec['_area']
- unset($var) - Similar to the way the basic variable works any args that are not unset will be tagged along to the end of the url
- Example 1: unset($args['id'])
- return value - The returned value is what the url will be ouput as
- Example 1: return $url
List
Category directories
- Area: - list
- Parameters: - c=*
- Format: - {list_url_structure()}
- Function: -
/**
* Changes to / for List URLS
*
* @param array $args Args passed over from sed_url
* @param array $spec Special info passed over from sed_url
* @return string
*/
function list_url_structure(&$args, &$spec)
{
global $sed_cat;
$url = str_replace('.', '/', $sed_cat[$args['c']]['path']).'/';
unset($args['c']);
return $url;
}
- Output Example: - articles/ or news/subcategory/
- .htaccess Example: -
RewriteRule ^(articles|news)/$ list.php?c=$1 [QSA,NC,NE,L]
RewriteRule ^(articles|news)/([a-z-]+)/$ list.php?c=$2 [QSA,NC,NE,L]
RewriteRule ^(articles|news)/([a-z-]+)/([a-z-]+)/$ list.php?c=$3 [QSA,NC,NE,L]
Pages
Pages alias and id with Category directories
- Area: - page
- Parameters: - *
- Format: - {page_url_structure()}
- Function: -
/**
* Changes to / for Page URLS
*
* @param array $args Args passed over from sed_url
* @param array $spec Special info passed over from sed_url
* @return string
*/
function page_url_structure(&$args, &$spec)
{
global $sed_cat, $pag, $row, $rpagecat;
$page_cat = (!empty($sed_cat[$rpagecat]['path']) && empty($page_cat)) ? $sed_cat[$rpagecat]['path'] : $page_cat;
$page_cat = (!empty($sed_cat[$pag['page_cat']]['path']) && empty($page_cat)) ? $sed_cat[$pag['page_cat']]['path'] : $page_cat;
$page_cat = (!empty($sed_cat[$row['page_cat']]['path']) && empty($page_cat)) ? $sed_cat[$row['page_cat']]['path'] : $page_cat;
$url = str_replace('.', '/', $page_cat).'/';
if($args['id'])
{
$url .= $args['id'];
unset($args['id']);
}
else
{
$url .= urlencode($args['al']);
unset($args['al']);
}
return $url;
}
- Output Example: - category/id or category/subcategory/alias
- .htaccess Example: -
#for page id
RewriteRule ^(articles|news)/([a-z-]+)/([a-z-]+)/([a0-9]+)$ page.php?id=$4 [QSA,NC,NE,L]
RewriteRule ^(articles|news)/([a-z-]+)/([0-9]+)$ page.php?id=$3 [QSA,NC,NE,L]
RewriteRule ^(articles|news)/([0-9]+)$ page.php?id=$2 [QSA,NC,NE,L]
#for page alias
RewriteRule ^(articles|news)/([a-z-]+)/([a-z-]+)/([a-zA-Z0-9-_]+)$ page.php?al=$4 [QSA,NC,NE,L]
RewriteRule ^(articles|news)/([a-z-]+)/([a-zA-Z0-9-_]+)$ page.php?al=$3 [QSA,NC,NE,L]
RewriteRule ^(articles|news)/([a-zA-Z0-9-_]+)$ page.php?al=$2 [QSA,NC,NE,L]
Please note the reason for the first set of names, is used to distinguish base directories to match, this can avoid complications with complex rewrites. Change the base to match your base categories or add more as needed. This only supports up 2 sub cats, but it can be copied to go deeper.
#7. -=== Basic htacces Information ===-
This section will give a few small tips for when building rules, it will not be a complete guide on how to build them
Flags - Flags are what is contained in [ ]
- QSA - Query String Append(QSA) causes any "GET"(?) data left in the url to still be sent along and is allowed to be processed
- NC - No Case(NC) causes the pattern to be considered Case-Insensitive
- NE - No Escape(NE) prevents the normal URI encoding of special characters to hexcode equivalent
Patterns
- escaping - As in PHP some special characters need to be escaped such as ".","(",")","[","]","\" if for some reason you have these in your pattern, you must place a "\" before them to escape them
- Example 1 - soemthing\.html
Thanked: 263 kez
But there are some problems.
"Users * by Username" isn't worked. It's give links "users/details" and redirect to users list
Also "Page by Alias" and "Page by ID" are conflicting. Parsing only that, what stay higher in list that is in admin.php?m=urls.
Thanked: 12 kez
... what about plugins?
Thanked: 12 kez
Or maybe indeed there's id/alias conflict
Thanked: 12 kez
I'm using Firefox.
Thanked: 12 kez
when using user by username style nice urls, the error appears:
Warning: urlencode() expects parameter 1 to be string, array given in /home/sth/ftp/cotonti/system/functions.php on line 4568
I'm using Cotonti beta 0.0.6
Thanked: 9 kez
Fixed the Page by Alias Rewrite rule
Added a rule to Username *
Tested them all all are working. Please note a couple things in this guide require 0.0.6 beta 2 or higher.
Thanked: 12 kez
I managed to make most of it work.
I'll try to write a function for forums (to display converted forum topics in url), it would be a blast! And very google-friendly.
But one question. Plugin "news" have out links: site.com/(page id or alias), but need to: site.com/news/(page id or alias). I try to add $cat to $pag['page_pageurl'], but it's only for "more". PAGE_ROW_URL is generating by sed_url.
Thanked: 9 kez
Those 2 functions are almost the exact we have here, except I removed the special bit for documents sections
Thanked: 12 kez
Thanked: 263 kez
Thanked: 12 kez
Thanked: 12 kez
Toplam: 17, on page: 15 12>>>