Joomla SEO, .htaccess, 301 redirects and Apache mod_rewrite

Joomla .htaccess and SEO for Dummies


The Joomla content management system provides a powerful, yet simple way for anyone to design a website. However, out of the box, a standard site is not set up with search engine optomisation (SEO) in mind. There are several simple rules that should be implimented into every Joomla Site to eliminate things such as duplicate urls and dynamically generated urls (unliked by search engines and hard for humans to remember). To standadize a www. or non www. prefix throughout the site. Also to create a better sitemap url for dynamic sitemap generators such as xmap.

We can achieve all of this on a linux server by using a .htaccess file. In this file we can use simple but powerful code to transform the way our Joomla site functions, such as:

A 301 redirect - This tells search engines and browsers that pages have been moved permanantly from one url to another.

Url Rewriting - Changing a dynamic url such as

to something more informative such as


So why do all this? A few examples and explanations....

Imagine you create an extremely interesting site which the whole world should see. As people start finding your site, they begin to link to it from their site as they think it will be interesting for their readers to see. With these links come a certain amount of pagerank, one of the factors which show how important your site is in relation to others. The more quality, high PR links, the higher the PR of your page.

Now imagine that your site is a standard installation of joomla. All of the following urls can be active, and all pointing to the homepage.


People can link to 1 page of your site using any of these urls which can result in your pagerank getting split between differing urls.

Eg, take this SEO companies website:

has a PR value of 5 (at the time I wrote this!) and

has a PR value of 4 (This can be seen using the google toolbar)


If the urls from this site were canonicalized (or normalised), the single homepage would have a higher PR resulting in better search engine visabillity for this PR company

This is the same with and without the www. prefix.

NB. Using googles webmaster tools you can inform the search engine of your prefered domain,, or, but this doesn't always help with linking. As good as google is, it still has some trouble finding a canonical page for some duplicates.

Anyway,what do we do about all this? The first thing is to FTP into your site or use your server control panel to view all the files that put your site together.

In the root of your site there is a file named


, download or open up this file to edit.


The first line that we are going to add is to force or remove the www. prefix. To force the site to display the www. we use the code below. Copy and paste it into you htaccess file underneath the line

RewriteEngine On



RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


To remove the www. and have your site appear as use the following:


RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]


Next we'll remove the /index.php from the homepage url. Underneath the lines you put in from above, maybe separated with a


symbol which is invisible to everything but you but helps to keep things readable, place the lines below.



RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.(php|html) [NC] 
RewriteRule ^index.php$ [R=301,L]


Or if you're using the non-www. version:


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.(php|html) [NC] 
RewriteRule ^index.php$ [R=301,L]


Now a simple 301 redirect to remove the /home from the homepage url selection with the following:


Redirect 301 /home

or, for the non-www. version:

Redirect 301 /home


Ok, so now we have the basics in our htaccess file we need to activate it.

Save the file and FTP it back to the server. As it is, the file will do nothing. We need to rename it from






Now the server will recognise the file and follow its directions.

Now that we have the .htaccess file active we can also instruct Joomla to create us some nice readable urls.

Log into the backend of your Joomla site and click on 'Global Configuration'. On the right you will see a box named 'SEO Settings'.

First of all we want to enable the 'Search Engine Friendly URLs' so click on yes.

We also want to use the .htaccess file we just created, so for 'Use Apache mod_rewrite' also click on yes.

The third box is a matter of personal preference, set to yes it will add the suffix .html to all of your pages, trying to make everyone think that it is a static page. I normally leave this off as it can be a pain in the arse for anyone to have to type anytime they want to see a page!

And that's all, if you now click on the preview button you should now be able to go through your site and see your new 'fancy' urls.

If you have any trouble following the directions above, I've created a demo file that you can download and change for your own site. This file will force the www. prefix. Download the file by clicking the link below.

Premade .htaccess file for joomla forcing www. prefix

To check that everything is in order SEO wise, use the tool from to check for any problems.

If you are using the Xmap component then please read this.


For more on rewriting techniques, read the definative guide to Apache rewriting by Rich Bowen

joomla rewritesjoomla for dummies