0845 205 0292

Request A Free Website Analysis

Close

Search Engine Friendly URLs (Apache and PHP)

March 5th, 2010 by

The concept is fairly simple. Make your website’s urls as readable as possible. If a human can read and remember the url, then you can bet your bottom dollar that search engines can as well. And THAT is the best way to approach this. If YOU can remember the url easily, then you have succeeded. If the url contains a huge query string with a lot of parameters that a person with an eidetic memory would have trouble memorising, then the search engines will have trouble following the links, you will lose rankings and that is bad for any seo campaign.

An example of a bad url is: http://www.example.com/index.php?p=156&c=55

An example of a good url is: http://www.example.com/category-name/product-name

How do we fix it?

This requires a lot of planning, and should be considered during the development of the site. In this example, we shall use a /file-name, /category-name/, /category-name/product-name approach. Basically, if there is sub-directory and no trailing slash, then treat the url as a file name. If there is a subdirectory, treat it as a category name, and if there is another section of the url then treat that as the product name.

There is a major problem with using a url structure like this, and that is having two or more categories or products with the same name. For this to work properly, each category must have it’s own name and each product within each category must have it’s own unique name.

In order to fix this we will need a little help from our old friend, the .htaccess file. I’ll show the code first, then dissect it.
RewriteEngine on

RewriteRule (.*)/(.*) index.php?c=$1&p=$2
RewriteRule (.*)/ index.php?c=$1
RewriteRule (.*) index.php?page=$1

The first line is telling the server to enable the mod_rewrite module. Without this, none of the following rewrite rules would work.

With me so far? The rest of the code gets a little more complicated. I’ll explain what each of the symbols is doing on it’s own, in context, and the end result. Hopefully this will allow you to make changes in the future as you need to.

There are thousands of tutorials on how to write regular expressions so I won’t go into very much detail here about everything. Consider this the basic of basics in order to accomplish a rather specific task.

In regular expression the period / dot – . – means any character except a new line. This is part of a group of commands called Ranges. They specify what to select, for example only select lower case letters, or some letters but not others, or only numbers, or only upper-case letters. This symbol will fetch ANY character, but only one, so we need to tell it to get as many characters as there are. We do this by using the asterisk / star – * -. This symbol is referred to as a Quantifier. A quantifier, as you may guess from it’s name, tells the expression how many of the range to get. This symbol means get 0 or more of the range. Putting it together, we get ‘Get 0 or more occurrences of ANY character’. Finally, the parenthesis (the brackets) mean ’save this content / group’. It saves the content in the format of $n, where n equals the number of groups that have been saved. As an example, in the line (.*)/(.*) will give us two groups of $1 and $2. These can then be used later in the expression.

With the basics covered, we’ll explain what each line is doing:

The second line is telling the server to separate everything before and after the slash and save them as variables $1 and $2 (respectively). It then loads the index.php file passing in the variables as part of a query string, where $1 is the category and $2 is the product.

The third line is fetching just everything before the slash as the category, and the final line is fetching everything as a page (for example a site-map or a terms and conditions page or some other information-based page).

It may look complicated but it really is quite simple, and the benefits are huge. Unfortunately, THAT was the easy part. The way pages generate links needs to be looked at so that they no longer have the query strings in them. It is pointless having the site process search engine friendly urls if your site is not using them. And then the way the index.php file loads and shows what is needed once the page has the query string needs to be addressed.

At SEO Consult we understand that this can be difficult to reverse implement into a website, which is why we strongly advice clients who are redesigning or redeveloping their sites to implement search engine friendly urls at the beginning of the development cycle, as it is much much easier to implement from the start of development than it is at the end of development.

This entry was posted on Friday, March 5th, 2010 at 4:00 pm . RSS GlobeYou can follow any responses to this entry through the RSS feed.

Link to us

If you want to link to this blog, copy and paste the following HTML code to your website.

Navigation

Blog Categories

Free SEO Analysis & Proposal

From The Blogread news

  • FEB 03
    I can’t really decide if the following is good news or bad news. A recent study in the journal Psychology Studies has found that the urge for a ‘Facebook Fix’ if you may, is just as strong, if not stronger than t...
  • FEB 02
    For those of you that follow any search engine optimisation blogs, or just SEO in general, then you will know of the bounce rate metric.  It sounds like a very innocent measurement, but in reality it can become the bane ...

Latest Newsread news

  • FEB 03
    The London Olympic and Paralympic Games is set to break a whole host of records as consumers demand for wireless access increases. Some 20,000 separate frequency arrangements are being allocated according to Ofcom. The 20,0...
  • JAN 30
    Figures recently published by Google have stated that in the next four years over 3bn people will be using the Internet or nearly a third of the world’s population. This has led to reports of an increase in Web Economy in G...

Clients Say...

"We've long been considering an SEO campaign and have researched the benefits that it could potentially bring to our web presence," commented 3663 Catering Equipment's Managing Director Paul Knight. "The team at Click Consult put together a very attractive package and we're pleased to be able to enter into a sound business partnership with them. We're looking forward to seeing the results they can provide for the 3663 Catering Equipment website moving forward."

3663

Managing Director - 3663 Catering

"We have been working with Click Consult for over a year now. We are delighted with the increase in unique visitors to our site and they have far exceeded our conversion KPI metrics for customer database registrations. We rank in the top 3 for all keywords that we asked Click Consult to optimize for us. This agency know how to produce results."

hills pets

Managing Director - Liverpool One

"Whilst we have a long term keyword strategy, Click Consult have a good appreciation of our business and have a flexible approach to implementing short term keyword strategies to coincide with the peaks of the retail calendar. I receive a monthly performance report from Click Consult detailing the relevant data I require but in addition, I can review the work being undertaken at any time by logging in to their bespoke reporting system."

hills pets

CRM Manager - Liverpool One

"Hills has been looking for an agency that is able to quickly deliver in the search marketing area and catapult EMEA websites ahead of the competition. Taking SEO Consult for this project turned out to be a smart choice. Not only have they managed to significantly increase search engine traffic to our websites, but they also come with innovative ideas that can be turned to reality. I can simply say they deliver. And it's always a pleasure talking to them."

hills pets

Managing Director - Hills Pets