I've got an application that has been migrated to a newer platform. The tasks are similar and I'd like to redirect a GET parameter to a directory. For example

```
http://gallery/index.php?gal=ABC  =>  http://photos/gal/ABC
  and
http://gallery/?gal=DEF           =>  http://photos/gal/DEF

```

and the anything that doesn't get caught redirect it to `http://photos`

I've tried

```
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^(/index.php)$ /%1/%2?

```

However all I get is a 404 and no redirection. Similarly, I've tried

```
RedirectMatch ^/index\.php\?=gal(.*) http://photos/gal/$1

```

but I'm having trouble escaping the `?` in the original URL.

What would be the proper way of going about this?