views:

24

answers:

2

The problem is roughly - I need a request path like this:

host/var1/val1/var2/val2/var3/val3/...

to be overwritten like:

host/index.php?var1=val1&var2=val2&val3=var3&...

Any ideas ?

+1  A: 

mod_rewrite isn't going to be able to parse key/value pairs on its own. Your best bet is to have index.php help out with the parsing.

Your .htaccess file would look like this:

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

Then you would use PHP at the beginning of index.php to set up the $_GET variable:

$params = explode('/', trim($_SERVER['REQUEST_URI'], '/'));

for ($i=0; $i<count($params); $i+=2) {
    $_GET[$params[$i]] = $params[$i+1];
}
jonthornton
A: 

Try these rules:

RewriteRule ^([^/]+)/([^/]+)/(.+) /$3?$1=$2 [QSA,N]
RewriteRule ^([^/]+)/([^/]+)$ index.php?$1=$2 [QSA,L]

But you’re better off with the PHP solution.

Gumbo