views:

19

answers:

1

I know the title is a little bit strange, but here is what the URLs look like:

/user/xxx/page
/user/xxx/page?error=yyy

The rule for the first URL looks something like this:

RewriteRule ^user/(\d+)/page$    something.pl?id=$1 [L]

And to make it work with the second URL, it becomes:

RewriteRule ^user/(\d+)/page(error=\d+)?$    something.pl?id=$1 [L]

My question is... how do I capture the error number? I tried both of these:

RewriteRule ^user/(\d+)/page(error=(\d+))?$    something.pl?id=$1&error=$2 [L]
RewriteRule ^user/(\d+)/page(error=(\d+))?$    something.pl?id=$1&error=$3 [L]

But it isn't working...

How can I do this?

+2  A: 

You can simply use the QSA flag to get the original query appended to the new one:

RewriteRule ^user/(\d+)/page$    something.pl?id=$1 [L,QSA]

Now a request of /user/xxx/page?error=yyy will get rewritten to /something.pl?id=xxx&error=yyy.

Gumbo