My url is being redirected using .htaccess as follows:

```
RewriteRule ^b/([^/]+)/([^/]+)? b/view.php?id=$2&name=$1

```

Friendly url -> translates to php url

`domain.com/b/hello/2 -> b/view.php?id=2&name=hello`

BUT when someone comes to the site as follows:

`domain.com/b/hello/2?query=xyz`

I don't know how to get rid of the `?query=xyz`

I have tried everything including [QSD] and I can't seem to get it to work.

**Update**

I have managed to get it to work with the following but it does two 301 redirects instead of one:

```
RewriteCond %{THE_REQUEST} \?[^\ ]+
RewriteRule ^b/(.*)$ /x/$1? [R=301,L]
RewriteRule ^b/([^/]+)/([^/]+)/([^/]+)?$ b/view.php?id=$2&&name=$1

```