简体   繁体   中英

htaccess mod rewrite with multiple query parameters

I can't quite get this redirect right. I want to redirect a legacy url http://www.example.com/product/page.php?item=AB123-AB123&upc=12345678910&c=1234

to

http://www.example.com/product/AB123-AB123

There will be variations of the url. ie google anlyatics tracking code or other query parameters. The only portion of the query string I need is item=AB123-AB123. I don't care about anything after that, although it would be nice to carry the remaining query string. http://www.example.com/product/AB123-AB123?upc=12345678910&c=1234

I have tried as suggested: RewriteRule ^product/([^/]*)$ /product/page.php?item=$1&upc=12345678910&c=1234 [L]

but I receive a 404 error. I've verified the resulting page is correct and active. ie http://www.example.com/product/AB123-AB123

Try :

 RewriteRule ^product/([^/]*)/?$ /product/page.php?item=$1 [QSA,NC,L]

Querystrings automatically get appended to the destination url.

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