SEO URL TOOLS - The Simple way to get pretty URL's on your PHP site

How does it work?

It is actually pretty simple. .htaccess file we set forwards any web request to index.php file. PHP script then takes over, parses url request and handles it. This approach allows flexible managing of url's, as we do not depend on any further Apache configuration. If any change in url handling is needed, it can be done through PHP. This allows us to actually define parameters we want to use through URL and even to change them when it is needed.

What is needed to know?

Using SEO URL TOOLS is actually very simple, as you saw in previous simple examples. Thing is that you have to understand how URL works and make the best possible use of it. Also you have to learn simple methods of handling URL information within your application to make it easily customized. Actually, all you ave to do is some settings, library would do most of the work for you, automatically.

Fist thing, you have to understand logic of URL we used. As you know, when you use SEO URL you have to decide about it's syntax. This means you have to decide meaning of each part of URL. Well, good news is that we already did that work for you. To make this library we had to decide about syntax of URL to be able to parse it properly and get all needed information. We decided on syntax that is pretty simple, easy to use and quite flexible, meaning, it should cover most of the needs one could have on his site.

SEO URL TOOLS supports two URL modes: standard query and pretty url (seo) mode. You are familiar with query mode, as that is nothing else but standard URL which in simplified form consists of host, path, document name and query parameters. It will work on any web server, regardless of rewrite engine.

Pretty url mode is our custom design. It cannot work if rewrite engine is turned off or not set properly. Althrough it looks similar to query mode it is very different. Every single item in URL except host is actually parameter. it is just mater of how we interpret those parameters.

First you have to learn about general definition of URL items. We defined them as this:

[scheme] scheme of the url (http/https/ftp....)
[user] username
[pass] password
[host] domain part of the url
[port] server port number
[root] root path of the site address
[doc] document name if in query url mode
[section] name of the section. It is actually the first directory item of the pretty url part of the url. Section item must match one of the predefined sections. If it does not match, then predefined default section is used, and not parsed from the url. you may use sections to separate different parts of the site. Most obvious example would be public and admin section. Your application may use this information to load different site template for different sections, apply different access rules etc...
[path] may contain none or more items separated by / each item is used as parameter. You may access them by order or by name if you set path names. As path does not provide names, names are distinguished from order of values provided in path. The first parameter is associated to the firth name in path names, second to the second etc... Path names should be custom defined. If not custom defined, p0, p1, p2, p3... will be used instead

Path defines exact document that should be loaded, together with optional additional parameters. For example, document may be news and parameter may show which exact news item to show.

[options] document options. Used for general options like language, page number or client type. Option items are separated by dots (.) and ordered. You may access them by name if you define them using url_add_param(). As option values are not named in url, names are associated due to type and value of the option. This class recognizes two types: numeric and char (string). Numeric type may contain numbers, and it is allowed to have just one numeric type option. String option may contain several predefined values. You set those values through url_add_param(). Althrough you may have several string options, they must not have the same values because name of the option is distinguished from it's possible values.

Document options are parameters that define different way of presenting document contents. IT does not affect information presented but the way how it is presented. That may be language definition, client type (web browser, PDF, PDA, RSS or other.

[query] query part of the url. items contain name and value, and you may access them by name. query values may always show as classic url query parameters (i.e. ?par1=val1&par2=val2)but in SEO URL's they also may show in path as /par1=val1/par2=val2/. ACtually, when string url is created the second syntax will be enforced in SEO URL's

Queries are additional general purpose parameters. May be used for anything needed.

[fraction] part of the url behind #

These items contain all information we may gather from URL and what is usually enough to easily define address for any document. There i one important note about this. path, options and query items may contain several sub items. Each sub item value may have two parts separated by dash (-). Part of value before the dash is actual element value. Dash and everything that follows is totally ignored. It may be used to insert item title or keywords that are meaned to improve SEO for the URL.

Let's see how they are used in URL:

For standard query url syntax is this:


How does this looks like when applied to real life address. We will not use all items, just those that are usually used:

Lets parse it:

[scheme] http this site is accessed using http protocol
[host] site domain is
[root] subsite root of the site is
[doc] index.php index.php is actual document
[section] admin url addresses admin section. you may use this information to check privileges or load different site template for admins
[path] [opt] = news
[item] = 12
path addresses actual document that should be displayed. [opt] shows that news should be loaded, and [item] is parameter that shows news item with ID value of 12 is loaded.
[options] [lang] = en language used on page is english
[query] [range]=today additional parameter for news item is today

I guess it seems a bit clearer now. Lets see how the same parameters look like when SEO url is used. For seo URL syntax is defined as:


Our example would look like this SEO url:

If we parse this SEO URL, we would get the same parsed data as from query URL, and that is the whole point of this library. You do not have to think about parsing, just about how to use parsed data.

It is important that you understand these elements that are used to build URL's, because in your application, you would not create URL's on your own. You will always let SEO URL TOOLS to create them by your instructions.

Built on DevCMS 0.1.4 and SEO URL Tools 1.0.38 - ©2007 Copyright by Predrag Supurović, ©2007 Copyright by DataVoyage