The default installation of PHP Fusion (
v6.00.307) and many other Content Management Systems produce what are generally considered to be search engine unfriendly URLs. For example /articles.php?cat_id=1. This article demonstrates how this behaviour can be changed in PHP Fusion so that URLs take on a static format and are rewritten in the form: /article-title-r1.htm.
Special note: To take advantage of this optimisation technique your site needs to be running on an Apache Web server which has mod_rewrite installed.
To keep things simple, we will be making changes to URLs which link to articles in articles.php but the procedure is the same for all other types of pages:
- decide on how you want your URLs to look
- add a rewrite rule (see the example below)
- modify script pages to generate static urls that match your rewrite rules.
Step 1: Download the code for
seoname.php from Len Johnson's
CVS Browser (click the disk). If you expect unusual characters in article titles you can edit this.
Step 2: Upload seoname.php to the
includes directory of your PHP Fusion installation.
Step 3: Make a backup copy of
maincore.php.
Step 4: Open maincore.php and find:
?>
Step 5: Immediately before, add:
// Search engine friendly URLs
// http://www.web-bureau.com/php-fusion-cms-c1.htm
require_once INCLUDES."seoname.php";
Step 6: Save your changes to maincore.php.
Step 7: Create a .htaccess file if you don't already have one and add the following to it:
## Use this if Fusion is installed in your root directory
RewriteBase /
## Use the following if Fusion is not installed on your root directory
## RewriteBase /<fusion_path>/
RewriteEngine On
Step 8: Upload .htaccess to the root directory of your PHP Fusion installtion.
Note: Now that is the basics of all the changes that are to follow, the following are block instructions for each section of the site that can have their URLs optimized. Follow any or all of the following depending on your needs.
For Articles & Article Categories
Step A1: Make a backup copy of articles.php.
Step A2: Open your .htaccess file and add the following,
## Articles
RewriteRule ^(.*)-r([0-9]*).htm$ readarticle.php?article_id=$2 [L,NC]
## Article categories
RewriteRule ^(.*)-c([0-9]*).htm$ articles.php?cat_id=$2 [L,NC]
Step A3: Open articles.php.
Find:
<a href='".FUSION_SELF."?cat_id=".$data['article_cat_id']."'>
and replace with
<a href='".seoname($data['article_cat_name'])."-c".$data['article_cat_id'].".htm'>
Find:
<a href='readarticle.php?article_id=".$data['article_id']."'>
and replace with
<a href='".seoname($data['article_subject'])."-r".$data['article_id'].".htm'>
Step A4: Save your changes and check your site to make sure all is working as it should be.
<--PAGEBREAK-->
For Downloads & Download Categories
Step D1: Make a backup copy of downloads.php.
Step D2: Open your .htaccess file and add the following,
## Downloads
RewriteRule ^(.*)-d([0-9]*).php$ downloads.php?download_id=$2 [L,NC]
## Downloads categories
RewriteRule ^(.*)-dc([0-9]*).php$ downloads.php?cat_id=$2 [L,NC]
Step D3: Open downloads.php.
Find:
<a href='".FUSION_SELF."?cat_id=".$data['download_cat_id']."'>
and replace with
<a href='".seoname($data['download_cat_name'])."-dc".$data['download_cat_id'].".php'>
Find:
<a href='".FUSION_SELF."?cat_id=$cat_id&download_id=".$data['download_id']."' target='_blank'>
and replace with
<a href='".BASEDIR.seoname($data['download_title'])."-dd".$data['download_id'].".php' target='_blank'>
Step D4: Save your changes and check your site to make sure all is working as it should be.
For Weblinks & Weblink Categories
Step W1: Make a backup copy of weblinks.php.
Step W2: Open your .htaccess file and add the following,
## Weblinks
RewriteRule ^(.*)-w([0-9]*).php$ weblinks.php?weblink_id=$2 [L,NC]
## Weblinks categories
RewriteRule ^(.*)-wc([0-9]*).php$ weblinks.php?cat_id=$2 [L,NC]
Step W3: Open weblinks.php.
Find:
<a href='".FUSION_SELF."?cat_id=".$data['weblink_cat_id']."'>
and replace with
<a href='".seoname($data['weblink_cat_name'])."-wc".$data['weblink_cat_id'].".php'>
Find:
<a href='".FUSION_SELF."?cat_id=$cat_id&weblink_id=".$data['weblink_id']."' target='_blank'>
and replace with
<a href='".BASEDIR.seoname($data['weblink_name'])."-w".$data['weblink_id'].".php' target='_blank'>
Step W4: Save your changes and check your site to make sure all is working as it should be.