Friday, 22 August 2014

Joomla 3 Search Engine Friendly URLs

Ok so I've been using Joomla in my new job for a while now. It was a bit of a learning curve as I had no previous experience with a CMS but now I'm getting used to it I can see me using it quite a lot with future websites. 
Although it has some limitations it is very good for small to medium size sites which could range from static website to a simple e-commerce site. There's a ton of extensions that can just be added on with little trouble.

You don't really need any coding experience to use it however it helps as some default features are not very SEO or user friendly. Today I'm going to go through process I do with each of my new Joomla sites to take care of things like SEO friendly URLs and removing the article number from URLs.
By default a link to an article in Joomla will look something like this, These perform very poorly in search engines as they mean nothing to nobody.

SEO Friendly URLs

Ok so the first step of this is quite simple. 
Within administrator > Global Configuration make the following changes:
Joomla SEO Settings
Switch Search Engine Friendly URLs and Use URL rewriting to Yes. Make sure Adds Suffix to URL and Unicode Aliases are set to No. This will change the URLs to something like: This Is already a lot better isn't it :). This however still won't work and the reason for that is the index.php in the URL. Next we will remove it.
Now that the first (and the easiest) step is over with lets get onto the trickier stuff. It's probably only 'tricky' for someone who has no experience editing a .htaccess file or no coding experience at all. I think anyone with even a small amount of experience won't be pushed too far out of their comfort zone if at all.
So in the next and final step of this part we need to update our .htaccess file. This can sometimes be tricky to find as it can be hidden by your computer or server (if using an in browser file manager). You will need to show hidden files in order to find this file. If you still can't find the file then it's possible you wont have one (typical of a new Joomla installation). If this is the case then open up a file called htaccess.txt in your root directory. This is your .htaccess file that if waiting to be used.
once you've opened it you need to search for the custom redirects section and add the following code:
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php/([^\ ]*)\ HTTP/
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^(([^/]+/)*)index\.php/(.*)$ http%2://$1$2 [R=301,L] 
Two more things you need to do is: 1, make sure that you remove all #'s at the start of any line we are editing otherwise it will be ignored. 2, replace with your own domain name.
This will now turn your URLs into much nicer SEO friendly and human readable URLs....almost. Your URLs will now look something like this This should work fine now (if not try going back to step one). However we still have the article number in the URL, which is pointless and potentially detrimental SEO-wise as well as being not very user friendly.
So now we're going to jump into a PHP file and sort that out.  

Step 1 Joomla 3.0.2:

Naviagate to and open  “components/com_content/router.php“, then continue on step 2. Remember, you’ll probably have to re-do this step every time you update Joomla.

Step 2 (There are two places need to do this change, one near the top, one in the middle) Replace this:

$advanced = $params->get('sef_advanced_link', 0);
With this:
$advanced = $params->get('sef_advanced_link', 1);

Step 3 You want to edit your router.php file:

- From: ->where($db->quoteName(‘alias’) . ‘ = ‘ . $db->quote($db->quote($segment)));
- To: ->where($db->quoteName(‘alias’) . ‘ = ‘ . $db->quote($segment));

You URLs should now look bloody gorgeous! If you do struggle with this for any reason (other versions of Joomla may differ in this process slightly) please contact me and I'll do my best to help you get sorted.

No comments:

Post a Comment