Many dynamic websites employ some sort of navigation achieved through the query string. For example:
Code:
http://www.htaccesselite.com/htaccess/posting.php?title=Mod_rewrite&action=edit
Just as this is difficult to read by humans, search engines also have trouble reading them. True, they aren't as bad as they used to be and engines like Google (
http://www.google.com) claim to read the query strings correctly. One part of the problem is that a query string items can be place in a different order. The page can still read and process the variables, but in essence the actual URL has changed.
The option is to place a .htaccess document in the root of the website, and re-direct any requests that are not actual files or directories to a file that will process the request. Below is the .htaccess document that re-directs all of those failed requests to an index.php file for handling. An added bonus of this is that you won't have to worry about any pesky 404 messages, your file will handle the navigation and you can output your own error message.
.htaccess document:
Code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]
Ok, now you have the .htaccess file in operation, you can use and address like:
http://wiki.dreamhost.com/Mod_rewrite/edit/1/It looks like a folder structure, reads much easier and also disguises how your page operates by not showing the query string variable names.
In the PHP page you could handle this navigation like so:
Code:
<?php
$navString = $_SERVER['REQUEST_URI']; // Returns "/Mod_rewrite/edit/1/"
$parts = explode('/', $navString); // Break into an array
// Lets look at the array of items we have:
print_r($parts);
?>
This page will output something like:
Code:
Array (
[0] = ,
[1] = 'Mod_rewrite',
[2] = 'edit',
[3] = '1'
)
You can use your imagination from there to create something that will navigate off the information you've extracted from the URI.
Note that rewrite rules in a .htaccess file behave differently from those in a server config. If you're used to writing rewrite rules at the server level, your habits will get you in trouble when working in a .htaccess file. In particular it is so far as I know *never* valid to begin a rewrite rule with a slash. A rule like
Code:
RewriteRule ^/anything http://other.server.com/somewhere
will never match, because the incoming URL never has a leading slash in directory context. This is explained in detail in the Apache documentation, see the resource links.