0

I need to capture a UID from an old url and redirect it to a new format.

example.com/?uid=123 should redirect to example.com/user/123

What should work...

RewriteCond %{QUERY_STRING} ^uid=(\d+)$
RewriteRule ^$ /user/%1? [L]

This does not redirect at all.

However, this does...

RewriteCond %{QUERY_STRING} ^uid=\d+$
RewriteRule ^$ /user/%1? [L]

It goes to example.com/user. The UID is left out, but it DOES redirect.

Notice: All I did was remove the parentheses in the second example.

Why is this?? How can I match the query AND capture the value of UID?

musicin3d
  • 141
  • 5
  • "Why is this??" - There is no difference in the directives/matching regex as posted, so that doesn't make sense. The parentheses simply make a capturing subpattern. However, neither of these rules match the example URL you've posted, ie. `example.com/uid?123`? So, as posted, these rules should "not redirect at all". (?) – MrWhite Apr 21 '20 at 23:42
  • @MrWhite That URL was a typo. It should have an query. I'll fix it. In regards to the other thing you said... Exactly. So it SHOULDN'T behave differently, but it DOES. Any ideas? – musicin3d Apr 22 '20 at 14:21
  • I'm moving this question to https://stackoverflow.com/questions/61369013/cant-use-parentheses-in-rewritecond-query-string because it's on topic there – musicin3d Apr 22 '20 at 15:35

0 Answers0