Clean URLs
Tiki supports search-engine friendly web addresses (SEFURLs or clean URLs), which are short versions of Tiki URLs, thanks to Apache Rewrite Rules. Some search engine crawlers do not process links with trailing parameters, so transforming the syntax makes the URL more search-engine friendly. By configuring your server properly, Tiki can understand clean URLs so that such short URLs will bring up a Tiki page, and by configuring Tiki properly, Tiki will produce clean URLS and build them into menus, static links, etc. This page explains both steps: how to make Tiki understand and produce clean URLs.Table of contents
Examples
Here are some examples of how clean URLs work for various types of Tiki pages:| Type of Page | Clean URL | Long URL |
|---|---|---|
| Wiki page|tiki.org/TikiRewriteRule | http://tiki.org/tiki-index.php?page=TikiRewriteRule | ||
| Forum|http://tiki.org/forum4 | http://tiki.org/tiki-view_forum.php?forumId=4 | ||
| Article|http://tiki.org/art133 | http://tiki.org/tiki-read_article.php?articleId=133 | ||
| Article|~~~body6~~ | ~~body7~~~ |
Note that both the short and long URLs will still access your site.
How to Activate Clean URLs
There are two basic steps to activivating Clean URLs:- Activating input rewrite rules on your server (so Tiki can understand clean URLs)
- With this step alone, accessing your site with clean URL short links will work properly
- Enabling the SEFURL or SEFURL Filter (version 3.0) feature (or both) in Tiki (So Tiki will produce clean URLs)
- This causes internal Tiki links to be rewritten into clean URLs. The generation of the clean URLs is governed with 'output rewrite rules' that are in the code before Tiki version 3.0 and in the database beginning with 3.0.
Step 1: Activate Input Rewrite Rules on Your Server
Web Hosting Service Using Apache
If you have Tiki version 1.9.x or greater and are using a web hosting service that uses Apache, then input rewrite rules can be activated as follows:- Rename the file named _htaccess in your Tiki root directory to .htaccess (or create a symbolic link to .htaccess).
- This will automatically bring in suggested rewrite rules shown below (at Suggested Input Rewrite Rules ) into the .htaccess file. The _htaccess file is included as part of the Tiki download (since version 1.9.3) but is not activated by default because it may not work with all server configurations.
Apache Configuration When Managing Own Server
If you manage your server and are using Apache, be sure to- Load the rewrite module. Something like this line in httpd.conf: LoadModule rewrite_module modules/mod_rewrite.so (adjust the path if necessary). You can check it is ok if you see the mod_rewrite in the apache loaded modules.
- Enable the access to .htaccess. To do so you must have lines like
<Directory "/"> ... Options FollowSymLinks AllowOverride FileInfo ... </Directory>
Adapt the directory path to your need. This block can be in httpd.conf or in your virtual host config (vhosts.d directory in apache2).
The documentation for Apache2 core says that the <FilesMatch> section requires:
AllowOverride All
- Restart your server
Web Servers Other Than Apache
If you or your web hosting company is using a web server other than Apache (IIS for example), see your server manual or contact your web hosting service to find out how to activate rewrite rules on your server.Suggested Input Rewrite Rules
Below are the rewrite rules for different versions of Tiki that pull into the .htaccess file automatically when the steps above for Apache web servers are followed.6.x version
Rewrite Rules for MultiTiki using Subdirectories as Symlinks
[+]Step 2: Configure Tiki to Produce Clean URLs
Now that your input rewrite rules have been set, you now need to configure Tiki to activate the output rewrite rules so that Tiki will generate SEFURLs internally in menus, static links and elsewhere.Changing Rewrite Rules
You can customize the rewrite rules but it is important to note that that the input and output rewrite rules are connected, so that if you change one you may need to change the other.- You can add as many input rewrite rules you want. For instance if you want to be able to access a forum with forum1 or forum_1, no problem. Add the adequate rule in the htaccess that will rewrite forum_1 to tiki-view_forum.php?forumId=1
- But if you want to change the output "rewrite" rules in Tiki, you must adapt the input rewrite rules
- Starting with Tiki version 3.0, the output rewrite rules are in the table tiki_sefurl_regex_out
WARNING: For sites hosted with MediaTemple's (gs) Grid-Service
After making these changes, your site may mysteriously revert back to using PHP4. This will result in an error such as the following when you try to access your site:Parse error: syntax error, unexpected T_STRING, expecting '{' in /nfs/c03/h01/mnt/GRID#/domains/YOURSITENAME.COM/html/tiki-install.php on line 45Resolve this by logging into the MediaTemple control panel and switching the site back to PHP5. Afterwards, double-check that your Search Engine Friendly url is still enabled in TikiWki.
Developer's Corner
The 'on the fly' filter can use 2 smarty tools: prefilter and a function. Here's an example:<img src="{$fileId|sefurl:thumbnail}" />
<a href="{sefurl page=$next_info.pageName structure=$home_info.pageName page_ref_id=$next_info.page_ref_id}">
<a href="{$listpages[ix].articleId|sefurl:article:with_next} show_comzone=y#comments">Both filters use tiki-sefurl.php to rewrite the urls.
