Personal tools
Home Webmaster Resources PHP Search Engine Friendly URLs

Search Engine Friendly URLs

When search engine optimization is high on your list, you want to avoid using the query string to pass information to pages. A more human- and search engine-readable method involves using the url path to pass information.

Example of a non-search engine friendly URL:

www.mysite.com/articles.php?id=45

Search engines, especially Google, have openly admitted that they pay far less attention and perhaps even ignore any link which includes an 'id' parameter in the query string.  In short, search engines prefer things the way they were in the early stages of the web, where all pages were static.  For example:

www.mysite.com/articles/how-to-make-search-engines-like-you.html

Of course, it isn't always possible to have a physical file for each url.  If you operate a user forum, you would have to create a new file on the file system each time a user creates a new thread.  Maybe not.

Web servers such as Apache are helpful in making search engines believe that an actual HTML file exists, when it doesn't at all.

Here's how Apache can help:


PATH_INFO

The AcceptPathInfo directive, when set to On, will capture pathname information that follows an actual filenameThe trailing pathname information can be made available to scripts in the PATH_INFO environment variable.  If we have a PHP file called index.php:

<? echo $_SERVER['PATH_INFO']; ?>

Run it with the following URL:

www.mysite.com/index.php/articles/how-to-make-search-engines-like-you.html

The output will be the following:

/articles/how-to-make-search-engines-like-you.html

If you were to store your articles in the database according to file name, instead of id, this path would be meaningful in identifying and displaying this article.  You also completely avoid having to pass any parameters in the query string.  Your resultant code would look similar to the following:

<?
$path = explode('/', $_SERVER['PATH_INFO']);  // split PATH_INFO into an array
$article_id = end($path);   // grab the last element in the path, which will be our article id

$sql = "SELECT name, body FROM article WHERE id = '$article_id'";
...
?>

Need assistance with your project? Universal Web Services can help.
Contact us to request a quote.