Search Engine Optimisation (SEO) Specialists

Search Engine Friendly URLs (Apache and PHP)

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.

Related posts:

  1. Link Rewriting for SEO
  2. Dynamically driving down SEO
  3. Canonicalisation and SEO
  4. Are your URLs friendly?
  5. Profiling queries with Zend

Tags: , , , , ,

Link to us

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

Leave a Reply

Search Blogs

Highest Rated Blogs

Tag Cloud

Recent Blogs

Blog Categories

About SEO
ASK SEO
Bing and Search Engine Optimisation
Black and White Hat SEO
Browser Software and Search Engine Optimisation
Cheap SEO
Clicktelligence & SEO
CMS and Admin Systems and SEO
eCommerce and Search Engine Optimisation
Email Marketing
Ethical Search Engine Optimisation
Flash and SEO
General SEO News
Geo Targeting Search Engine Optimisation
Google Analytics
Google and Search Engine Optimisation
Google PageRank
Google PR Update
Google Webmaster Tools
Increase Search Traffic with SEO
International SEO
Internet Marketing
Keyword Research and Search Engine Optimisation
Latest News
Link Campaigns and Search Engine Optimisation
Meta Tags and SEO
Mobile SEO
Offpage Optimisation
Online Advertising
Onpage Optimisation
Page Load and SEO
Page Rank Update
Pay Per Click & SEO
Press Releases
Professional SEO
Real Time Search
Search Engine Indexing and Crawling
Search Engine Optimisation
Search Engine Optimisation Advice
Search Engine Optimisation Analysis
Search Engine Optimization
Search Engine Optimization Keywords
Search Engine Optimization Marketing
SEO Analysis for Results
SEO and Business
SEO and Search Engines
SEO Blogging
SEO Companies
SEO Consult
seo consultancy
SEO Copywriting
SEO Costs
SEO Domain Names
SEO Experiment
SEO Links
SEO Lists
SEO Management
SEO Penalties
SEO Rankings
SEO Sitemaps
SEO Strategy
SEO Submissions
SEO Techniques
SEO Tips
SEO Tools
seo video
SEO vs PPC
Site Analysis and Search Engine Optimisation
Site Architecture & SEO
Social Media Optimisation
Social Networking and Search Engine Optimization
Target Marketing with SEO
Top SEO Tips
Traffic & SEO
Twitter and Search Engine Optimisation
User Driven SEO
W3C and Search Engine Optimisation
Web Design
Website Development
Website Optimization
Wordpress For SEO
Yahoo! and Search Engine Optimisation
View All Categories

Archives

Authors

SEO Discussion Board from SEO Consult SEO Consult Resource Centre for Search Engine Optimisation
W3C XHTML Valid W3C CSS Valid W3C WAI  Internet Marketing RSS Feed for SEO Consult