al404IT
al404IT

Reputation: 1418

redirect 301 with query string doesn't seem to work

I need to redirect some URL with query string to a different URL

like

 redirect 301 /web/works/?id=1  https://www.example.com/it/my_work_new_page/

.htaccess seem to ignore this

but if i add

redirect 301 /it/fake/  http://www.test.it

it works

I already have a file with about 100 of this redirect

Upvotes: 1

Views: 351

Answers (1)

anubhava
anubhava

Reputation: 785128

You cannot match query string using Redirect directive. Use mod_rewrite with a RewriteCond directive like this:

RewriteEngine On

RewriteCond %{THE_REQUEST} /web/works/\?id=1\s [NC]
RewriteRule ^ https://www.example.com/it/my_work_new_page/? [L,#=301]

? in the target will strip previously existing query string.

References:

Upvotes: 1

Related Questions