So far I\'ve done this:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?load=$1 [QSA,L]
What you want is what is known as an URL router, this requires you to analyze the url and make decisions based on the contents. Most systems do this by getting you to provide an url template, and a function to call if the url matches. The function is normally passed any sub-matches in the template url.
For example Django uses regexes for its url routing and passes the named matches as arguments to a given function (or class).
If this is too complex for your needs then you can just use specific regexes to parse the url, your gallery case would be:
$matches = array();
$re = "/\/([\w\d])+\/([\w\d+%])+\/?/";
preg_match($re, $load, $matches);
$username = $matches[0];
$gallery = $matches[1];
you can then use $username
and $gallery
however you wish.
Note
The above assumes that it will match, you will need to check the return value of preg_match
to make sure. Also, I have not checked the regex, it may be wrong, or use features not in this syntax.
Reference