I've got a couple of php files that perform a couple of different jobs. Let me alter the way my clients access these php files to really make it more clean for that consumer. The Mod_Rewrite system has proven that it may perform some pretty effective things when at the disposal of the best server admin. So I'm wondering what lengths are you able to abuse the Mod Rewrite rules for any cleaner file system, and pretty Web addresses. Thinking about the PHP files themselves use query strings to have their data, Let me alias how a query string is made based on the way the how deep in to the fake files system we go.

Our website's URL is http://www.domain.tld/, but we shall refer to it as domain.tld for brief. Let me map a couple of different address to some couple of different query strings on the couple of different files. But I'd like to to become expanding on impulse.

Or first set could be, anything going past domain.tld/series/ ought to be forwarded to the domain.tld/series.php script with any (fake) directory past series to end up part of the query-string for series.php. Exactly the same happen to anything directed in direction of domain.tld/users/ that needs to be rerouted towards the domain.tld/users.php file.

Therefore if we'd a Web addresses like, domain.tld/series/Master/2010/ or domain.tld/series/Novice/Season 01/ they'd be rerouted towards the domain.tld/series.php script, however with the query-string of ?0=Master&1=2010 and ?0=Novice&1=Season 01. But should I wish to get an introduction to the actual series, I possibly could go the the URL domain.tld/series/Master/ and convey the query-string of just ?0=Master. The concept since the rewrite rule should permit infinite expandability.

This is the way I am doing the work, also it sure works infinitely:

RewriteRule ^((/?[^/]+)+)/?$ ?q=$1 [L]

The secret would be that the whole path is handed down like a single parameter, q, to index.php. So for instance domain.tld/series/Novice/Season 01/ becomes domain.tld/?q=series/Novice/Season 01. You'll be able to do:

$params = explode('/', $_GET['q']);

to obtain the individual parts.

array(3) { 0 => 'series', 1 => 'Novice', 2 => 'Season 01' }

It's not easy to be completely dynamic in this system and also have, while you say 'infinite expandability. You would need to define a RewriteRule for each 'tier' you'll allow inside your URL, or else match everything following the first 'tier' like a single variable and perform the use PHP.

Example 1

RewriteRule ^([^/]+)/?$ /$1.php
RewriteRule ^([^/]+)/([^/]+)/?$ /$1.php?0=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /$1.php?0=$2&1=$3

Example 2

RewriteRule ^([^/]+)/(.*)/? /$1.php?qs=$2

Clearly they are only quite simple good examples and you'd most likely need to use RewriteConds etc. to exempt certain files etc.