[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Apache Rewrite rule help needed, please

Hi, I need help tweaking a mod rewrite.


Right now users can come to my site with a url of http://site.com/catalog/product/123 (or /catalog/product/123/)

And it's rewritten to http://site.com/catalog/product.php?itemNo=123

Here's the rule(s) that do that:

RewriteRule ^/catalog/product/([A-Za-z0-9]+)$ /catalog/product.php?itemNo=$1 [L]
RewriteRule ^/catalog/product/([A-Za-z0-9]+)/$ /catalog/product.php?itemNo=$1 [L]


However, I need to be able to support additional parameters on the URL and carry them along in the rewrite... so for example, if the user comes to

http://site.com/catalog/product/123?v1=abc&v2=def

Then I need that to be rewritten to:

http://site.com/catalog/product.php?itemNo=123&v1=abc&v2=def

The extra vars won't always be "v1" and "v2" -- I need a rewrite rule that will keep it open and just carry along whatever GET parameters were appended to the URL.

I've tried many times over to get this working, without luck ;-) Please help!

thank you---

best
Eric
0
pnoeric
Asked:
pnoeric
1 Solution
 
HackneyCabCommented:
Does it not work if you append the query string using the server variable, like this:

RewriteRule ^/catalog/product/([A-Za-z0-9]+)/?$ /catalog/product.php?itemNo=$1&%{QUERY_STRING} [L]

(I've collapsed the rules into one by making the final forward-slash optional.)
0
 
pnoericAuthor Commented:
yes! thank you so much.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now