user125264
user125264

Reputation: 1827

Ionics Isapi Rewrite Filter - Special rule for ? in url

Im relatively new to the ionics rewrite filter and im trying to configure my ruleset to allow for additional dynamic rules for my app. I currently have the following rules defined for my shop part of my application.

RewriteRule ^/shop/(.*)/pages/(.*) /index.cfm?go=shop.products&content=$1&CurrentPage=$2 
RewriteRule ^/shop/(.*)/pages/(.*)/ /index.cfm?go=shop.products&content=$1&CurrentPage=$2 

RewriteRule ^/shop/(.*)$ /index.cfm?go=shop.products&content=$1 
RewriteRule ^/shop /index.cfm?go=shop.products 
RewriteRule ^/products.cfm  /index.cfm?go=shop.products 
RewriteRule ^/details.cfm   /index.cfm?go=shop.products 

A service provider is saying we arent allowing for additional tracking variables to be passed in unless they prefix it with an & symbol.

the URLs look like the below.

www.domainname.com/shop/category-of-products 
www.dimainname.com/shop/ 

with their additional variables they must do as follows

www.domainname.com/shop/category-of-products&additional-query-strings 
www.dimainname.com/shop/&additional-query-strings 

what they need to do is

www.domainname.com/shop/category-of-products?additional-query-strings 
www.dimainname.com/shop/?additional-query-strings 

what is it that i need to do to allow for the additional ? to be referenced

Any help greatly appreciated

Upvotes: 1

Views: 783

Answers (2)

marapet
marapet

Reputation: 56486

You may try changing the rewrite's regular expression to allow optionally for any query string parameter.

For example:

RewriteRule ^/shop/(.*)$ /index.cfm?go=shop.products&content=$1

becomes

RewriteRule ^/shop/(.*)(\?.*)?$ /index.cfm?go=shop.products&content=$1

The additional (\?.*)? makes the expression match question mark and everything that follows for 0 or one time.

I can't test it right now, but I think you may even need make the first matching group non greedy by adding a ? after the star:

RewriteRule ^/shop/(.*?)(\?.*)?$ /index.cfm?go=shop.products&content=$1

By the way: This adds three question marks to your regex, each one with a different meaning - make preceding operator non greedy, match a literal question mark, and match the preceding expression 0 or 1 time.

Upvotes: 0

Mike Schell
Mike Schell

Reputation: 36

You may be able to take advantage of the $args variable.

Try adding &$args? at the end of your rewritten URLs. The ? at the end makes sure Nginx isn't going to add the query string again automatically.

e.g.

RewriteRule ^/shop/(.*)$ /index.cfm?go=shop.products&content=$1&$args?

Upvotes: 0

Related Questions