PhpRiot
Download This Article
Download this article in PDF format with all listings and files.

Price: $5.00 AUD
(Approx. $4.45 USD)

More information
Related Books
Professional Search Engine Optimization with PHP: A Developer's Guide to SEO

Professional Search Engine Optimization with PHP: A Developer's Guide to SEO

Maybe you’re a great programmer or IT professional, but marketing isn’t your thing....
Browse Articles
Ajax (4), APC (1), CAPTCHA (1), CSS (3), Debugging (1), File Upload (1), Google (3), Google Maps (2), JavaScript (12), JSON (2), MVC (1), MySQL (7), onbeforeunload (1), OOP (1), PHP (28), PhpDoc (1), PostgreSQL (6), Prototype (11), Reflection (1), RFC 1867 (1), Robots (1), Scriptaculous (1), SEO (1), Sessions (1), SimpleXML (1), Smarty (5), SOAP (1), SPL (1), Templates (2), W3C (1), XHTML (1), Zend Framework (1), Zend_Search_Lucene (1)

PhpRiot Newsletter
Your Email Address:

Creating Search Engine Friendly URLs In PHP

Introduction

Note: This article was updated in February 2008 to include the "Using mod_rewrite as a 404 Handler" page, since using ErrorDocument in Apache results in POST data being unavailable.

One of the major reasons for using a server-side language such as PHP is for the ability to generate dynamic content. Often this will lead to single scripts that produce their content based on the input parameters (that is, the variables in the URL).

This article covers various techniques and methods for representing these parameters in the URL in a clean and “friendly” manner, as well as then how to read the parameters.

If you’re not quite sure what I mean, take the following example. This website (PhpRiot) stores each of its articles in a database table called articles. Now, we could have built the site so all articles were referenced by their article ID, such as:

  • http://www.phpriot.com/article.php?article_id=1234

However, this isn’t necessarily the best way to do it. Firstly, if people have read a large number of articles on the web site, then their URL history will contain a whole bunch of different IDs, so they won’t be able to directly back to an article without either bookmarking it or visiting the home page and finding the link.

More importantly though, this is wasting valuable data that the search engines can use in indexing your site. PhpRiot has been built in such as way that each articles are accessed in a more human-readable format. For example, a previous article on this site is accessed with the following URL:

  • http://www.phpriot.com/articles/multi-step-wizards

This article will go over how read URLs like this and map them back to the data in your database. There are several methods that can be used with PHP, so we will cover each of these and discuss the pros and cons of each.

Additionally, the ideas used in these may cross-over between each method (such as the manual parsing of URLs), but we will also go over this.

In This Article


Tagged in ,

Article History

Jan 10, 2006
Initial article version
Feb 27, 2008
Added the "Using mod_rewrite as a 404 Handler" page to the article