If you want to simply ignore all parameters, then you can still use a standard
Redirect, because it is prefix matching and does not match against the query string anyway. For example:
Redirect 301 /slug1/slug2/slug3 /slug4
Redirect would 301-redirect all the URLs in the question (ie. all URLs that start
However, any query string on the requested URL will also be passed through to the target URL unaltered. So,
/slug1/slug2/slug3?ref=2 will be redirected to
/slug4?ref=2. If this is undesirable, and you wish to remove the query string entirely*1, then you will need to use mod_rewrite (ie.
RewriteRule), rather than mod_alias (ie.
RedirectMatch, as suggested in the other answer) in order to explicitly remove the query string completely from the target URL. For example:
RewriteRule ^slug1/slug2/slug3$ /slug4? [R=301,L]
? on the end of the
RewriteRule substitution will result in the query string being removed from the target URL (you could alternatively use the
QSD flag on Apache 2.4+). The query string is not matched by the
RewriteRule pattern, so there is nothing extra you need to do in this respect, unless you needed to match specific query strings, or only when there is actually a query string (the above will match regardless of whether a query string is present or not).
An additional caveat with switching to a mod_rewrite redirect is that you should ideally change any existing mod_alias redirects to the equivalent mod_rewrite syntax. This is to avoid any potential conflicts since the two modules execute at different times.
*1 Note that you can simply append a
? (ie. an empty query string) on the end of the target URL with the
RedirectMatch directives. However, the trailing
? is actually included in the redirected URL, as opposed to be being removed entirely, as with a mod_rewrite