You can't match the query string in the RewriteRule
pattern. You need to use a RewriteCond
directive and compare against the QUERY_STRING
server variable.
But also, assuming you have an internal rewrite later in your config file that rewrites back to the (real) ugly URL then you can't do a simple redirect, as it will result in a redirect loop. You need to make sure you only redirect the initial request, not the rewritten URL.
Assuming this is .htaccess
, based on your existing RewriteRule
pattern, try the following, near the top of your config file:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^toolid=(/d+)$
RewriteRule ^somePage\.php$ /tool/%1 [R=301,L]
Note, however, that your example URLs differ from your code example. I've gone with your code example.
The REDIRECT_STATUS
environment variable is empty on the initial request, but gets set to "200" after a successful internal rewrite. So, this avoids a redirect loop in per-directory .htaccess
files.
Make sure you've cleared your browser cache, since any erroneous 301s (whilst testing) will have been cached by the browser.