简体   繁体   中英

Htaccess remove query string from 301 redirect

I write 301 redirect as below

Redirect 301 /catalogue/novelty_linen_q_t/spongebob_squarepants/spongebob_squarepants_quilt_cover_wonderland/image/?size=275x275&helper=1281395930.79 http://www.thebedroom.com.au/manchester/character-bedding.html?size=275x275&helper=1281395930.79

but when I goes to http://www.thebedroom.com.au/catalogue/novelty_linen_q_t/spongebob_squarepants/spongebob_squarepants_quilt_cover_wonderland/image/?size=275x275&helper=1281395930.79

it redirect http://www.thebedroom.com.au/manchester/character-bedding.html?size=275x275&helper=1281395930.79

........ I need redirect http://www.thebedroom.com.au/manchester/character-bedding.html

Remove the query string from your Redirect directive, this is what you have: (make sure to scroll all the way to the right to see the comments)

#                                                                                                                           This question mark right here is why you have a query string in your redirect ---------v
Redirect 301 /catalogue/novelty_linen_q_t/spongebob_squarepants/spongebob_squarepants_quilt_cover_wonderland/image/?size=275x275&helper=1281395930.79 http://www.thebedroom.com.au/manchester/character-bedding.html?size=275x275&helper=1281395930.79

Not really sure why it's working at all, but you need to remove everything AFTER the ? , leaving the ? there. That does have the unsightly side-effect of a stray question mark, but you can get rid of that using mod_rewrite, replacing the Redirect with:

RewriteEngine On
RewriteRule ^catalogue/novelty_linen_q_t/spongebob_squarepants/spongebob_squarepants_quilt_cover_wonderland/image/?$ /manchester/character-bedding.html? [L,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM