Category >> CMS

Feb 28
2008

Howto: 100% Search engine friendly URLs in Joomla!

Posted by tcallway in PHPOpen SourceMySQLLAMP stackJoomla!GPLDebianCMSARTIO JoomSEFApache

Joomla! logo

Implementing 100% SEF URLs in Joomla! can be a little tricky so we've written a step-by-step guide that includes how to correctly configure your LAMP server.

There are some differences in implementing SEF URLs in Joomla! 1.0.* and 1.5, principally the requirement for third-party plugins.

We'll deal with the generic LAMP server configuration issues first and then deal with the different versions of Joomla! in turn.

Assumptions

In this howto we've made some assumptions about your web server set-up, your permissions level and your familiarity with the command line. If you only have FTP access then your might have a few difficulties.

  • Operating system - Debian Linux with root access (there will be differences if you use a non-Debian derived Linux distribution)
  • Text Editor - VIM
  • Web server - Apache2 (correctly configured for use with MySQL and PHP)
  • Database - MySQL

Generic LAMP server configuration

SSH to your web server. In the website's root (e.g. /var/www/) do:

# mv htaccess.txt .htaccess

# vi .htaccess

Edit your .htaccess and it should like this:

==========================================
#
# For Standard SEF, use the standard SEF section.  You can comment out
# all of the RewriteCond lines and reduce your server's load if you
# don't have directories in your root named 'component' or 'content'
#
# If you are using a 3rd Party SEF or the Core SEF solution
# uncomment all of the lines in the '3rd Party or Core SEF' section
#
#####################################################

#####  SOLVING PROBLEMS WITH COMPONENT URL's that don't work #####
# SPECIAL NOTE FOR SMF USERS WHEN SMF IS INTEGRATED AND BRIDGED
# OR ANY SITUATION WHERE A COMPONENT's URL's AREN't WORKING
#
# In both the 'Standard SEF', and '3rd Party or Core SEF' sections the line:
# RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
# May need to be uncommented.  If you are running your Joomla/Mambo from
# a subdirectory the name of the subdirectory will need to be inserted into this
# line.  For example, if your Joomla/Mambo is in a subdirectory called '/test/',
# change this:
# RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
# to this:
# RewriteCond %{REQUEST_URI} ^(/test/component/option,com) [NC,OR] ##optional - see notes##
#
#####################################################


##  Can be commented out if causes errors, see notes above.
Options FollowSymLinks

#
#  mod_rewrite in use

RewriteEngine On


#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.
#  Update Your Joomla/MamboDirectory (just / for root)

RewriteBase /

########## Begin Standard SEF Section
## ALL (RewriteCond) lines in this section are only required if you actually
## have directories named 'content' or 'component' on your server
## If you do not have directories with these names, comment them out.
#
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR]       ##optional - see notes##
#RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$  [NC]
#RewriteRule ^(content/|component/) index.php
#
########## End Standard SEF Section


########## Begin 3rd Party or Core SEF Section
#
#RewriteCond %{REQUEST_URI} ^(/shoptest/component/option,com) [NC,OR]       ##optional - see notes##
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$  [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php
#
########## End 3rd Party or Core SEF Section
==============================================

Change the RewriteBase variable to the root of your Joomla! install. For example if you've put it in /var/www/joomla this variable should read:

RewriteBase /joomla

Otherwise leave it as it is.

Now in your terminal:

# vi /etc/apache2/sites-available/default

In this file change references to:

AllowOverride None

to:

AllowOverride All

Save and exit.

Now you need to install the mod_rewrite plugin into Apache. In your terminal run the following command:

# a2enmod rewrite

Reload your Apache webserver with the following command:

# /etc/init.d/apache2 force-reload

With Joomla! 1.0.*

ARTIO JoomSEF

Download and install the component ARTIO JoomSEF from the Joomla! extensions website.

There are other SEF extensions available in Joomla! but ARTIO JoomSEF uses an Open Source license and seems to work very well.

Make sure that you turn on ARTIO JoomSEF in the Configuration section of the Component.

In the Joomla! Admin Panel goto Global Configuration and click the SEO tab. Select Yes to both 'Search Engine Friendly URLs' and 'Dynamic Page Titles'.

With Joomla! 1.5

Joomla! 1.5.1 was recently released and is now officially stable. If Joomla 1.5 supports all the plugins you want then it's probably worth upgrading to it. If not, then stick with Joomla 1.0.*.

One of the great advantages of using Joomla! 1.5 is that it includes SEF URLs out-of-the-box. This makes plugins like ARTIO JoomSEF unnecessary.

So, once your LAMP server is correctly configured, goto the Admin Panel select  Global Configuration. Select Yes to 'Search Engine Friendly URLs', 'Use Apache mod_rewrite' and 'Add suffix to URLs' (optional) and save.