regex with query string containing?

时间:2018-02-01 18:35:27

标签: regex .htaccess

I am trying to redirect the following URL: url/efx.aspx?xxxxxxx to url/car-audio/efx-hardware/amp-install-kits

However it is redirecting whatever contains efx.aspx with the letters without the ? sign. I was wondering how I can fix this?

for example it is redirecting the following:
domain.com/efx.aspxlsdkjfhlasdf
but it is not redirecting
domain.com/efx.aspx?lsdkjfhlasdf

here is the .htaccess rule I wrote. how can I correct it?

RewriteCond %{REQUEST_URI} /efx.aspx[^/]+$
RewriteRule (.*) /car-audio/efx-hardware/amp-install-kits [R,L]

1 个答案:

答案 0 :(得分:0)

You can use this rule:

RewriteRule ^efx\.aspx$ /car-audio/efx-hardware/amp-install-kits? [R=301,NC,L]
  • Query string is not part of REQUEST_URI hence [^/]+ after efx.aspx fails your rule.
  • Also ? at the end of target URI removes any existing query string.