Using URL Rewriter query-string condition

Hi,

My colleagues are trying to add a url rewriter rule, which basically adds a query string to the url. The rule causes the browser to keep on redirecting until it stops with an error. I added a condition to make the rule only trigger when the query string is empty, but it seems the condition is not being applied at all.

For example:

/example-rule:
  jcr:primaryType: urlrewriter:advancedrule
  urlrewriter:casesensitive: false
  urlrewriter:isnotlast: false
  urlrewriter:iswildcardtype: true
  urlrewriter:qsappend: false
  urlrewriter:ruledescription: ''
  urlrewriter:rulefrom: /example
  urlrewriter:ruleto: /example?q=value
  urlrewriter:ruletype: permanent-redirect
  /urlrewriter:rulecondition:
    jcr:primaryType: urlrewriter:rulecondition
    urlrewriter:conditionname: ''
    urlrewriter:conditionoperator: equal
    urlrewriter:conditionor: or
    urlrewriter:conditiontype: query-string
    urlrewriter:conditionvalue: ''

I also tried this:

/example-rule:
  jcr:primaryType: urlrewriter:advancedrule
  urlrewriter:casesensitive: false
  urlrewriter:isnotlast: false
  urlrewriter:iswildcardtype: true
  urlrewriter:qsappend: false
  urlrewriter:ruledescription: ''
  urlrewriter:rulefrom: /example
  urlrewriter:ruleto: /example?q=value
  urlrewriter:ruletype: redirect
  /urlrewriter:rulecondition:
    jcr:primaryType: urlrewriter:rulecondition
    urlrewriter:conditionname: q
    urlrewriter:conditionoperator: notequal
    urlrewriter:conditionor: or
    urlrewriter:conditiontype: parameter
    urlrewriter:conditionvalue: value

Why isn’t this working? Is there a recommended approach to get this to work?

Regards,

Maarten

Hi Maarten.

what is the setting for urlrewriter:usequerystring property?

A quick test of following rule works locally:

Hi Machak,

it is set to false. So I suppose I cannot use the conditions to take the query string into account only on some of the rules? For most rules (and we have a lot) the query string should not be used when matching.

I tested above rule with “false” value and I get a redirect if I don’t have “lang” query string defined.

/urlrewriter:rulecondition:
  jcr:primaryType: urlrewriter:rulecondition
  urlrewriter:conditionname: ''
  urlrewriter:conditionoperator: notequal
  urlrewriter:conditiontype: query-string
  urlrewriter:conditionvalue: (?:^|&)lang=

I got it to work in the way you suggested. Didn’t get it to work with wildcard matching on.

So the issue is solved now. Thanks!