You can deal with this by writing a function, which generates URLs for you. This function would obviously know about the rewrite rules. Just a simple example, to illustrate:
PHP Code:
function url($href, $args = Array()) {
foreach ($args as $key => $value) {
if (!is_null($value)) {
if (is_integer($key)) {
$params[] = rawurlencode($value);
} else {
$params[] = rawurlencode($key)."=".rawurlencode($value);
}
}
}
if (count($params) > 0) {
if (strpos($href, "?") === FALSE) {
return "?".implode("&", $params);
} else {
return "&".implode("&", $params);
}
}
}
// http://www.domain.com/gallery.php?id=1&pg=2&filter1=1&filter2=0&
url("gallery.php", Array('id' => 1, 'pg' => 2, 'filter1' => 1, 'filter2' => 0));
This will generate a "normal URL. You can then modify url() to generate it in your rewrite-scheme.
That all said, I think you clearly went overboard with the URL-rewriting here. If the parameters are optional, and non-hierarchical in nature, they don't really belong in the path-part of your URL. They rightfully belong as queryString parameters (GET-params in PHP-lingo). A good measure is to look at if the order of the parts of the path is random, or has meaning. If the order doesn't matter, then you should probably have used the queryString instead.
Bookmarks