Page 2 of 4
Using the Joomla framework
So how can we add a Tiny URL facility to Joomla or any similar PHP based website that uses a database? We could implement a new component or modify the Joomla code to do the job but both approaches have problems. Creating a component seems like overkill for such a simple task and modifying the Joomla code is a big step that isolates you from any future developments. A much simpler and risk free way of doing the job is to write a standalone PHP page that converts the incoming URL and redirects to a standard Joomla format URL.
The basic idea is that the tiny URL will take the form:
and will display the article with ID 45 as if the user had clicked a link within your website in the usual way. Notice that every article has a unique ID number that you can see listed in the far right hand column within the Article Manager.
The task of the tinyURL.php page is to take this URL and convert it into a full Joomla style URL - of course if you're not using Joomla the conversion will be different but it’s the same principle.
A standard, i.e. non-SEOed, Joomla URL structure is:
Actually Joomla 1.5 uses an even longer version of this URL structure with some additional features designed to be more human readable. However the basic URL structure still works and it works even if you have SEO URLs turned on.
option= com_content &task= article&
Let's look at each part of the URL in turn:
Every page in your web site is built by index.php it’s the master and usually only entry point to Joomla. It takes your template and loads menus, components and articles to build every page the user views
The option specifies which component will be loaded to build the major part of the page. This more or less determines the pages function. For example option=com_content loads the content component ready to display an article.
The task specifies what the component specified by option is to do and the majority of cases we have task=article to display the components standard appearance. Other values of task depend on the component being loaded.
This is the ID number of the article to be loaded. It is used by Joomla to retrieve the article from the database.
This is the one that confuses everyone. It is the unique ID of the menu that the user clicked on. When you define components in a Joomla site you specify which menus they are associated with and when the user arrives at a page via that menu the components associated with it are loaded. In theory all Joomla pages have to have an Itemid but many will work without one. However the value of the Itemid you specify will often alter the look of the page by loading different components to surround the main article. As you can guess in reconstructing a full Joomla style URL the Itemid is going to be a problem.
So now you can see that our earlier example:
option= com_content &task= article
means load the com_content component and pass it the command "article". This causes it to load and display article 45 plus any components associated with menu id 3.