URL rewriter and query-strings (in upper- and lowercase)

716 views
Skip to first unread message

Edwin B.

unread,
Feb 18, 2016, 5:28:48 AM2/18/16
to Hippo Community
Hi,

How can I redirect 

from:
/dosomething.asp?code=1234 
or
 /dosomething.asp?CODE=1234
(mind the difference: code and CODE in the querystring).

to:
/dosomething/code/1234


When I create an Advanced rule with:

Case sensitive: false

Condition:
- type=parameter
- type parameter=code
- operator=equal
- value=(.*)

Rewrite from: /dosomething.asp

Rewrite to: /dosomething/code/%1

it rewrites correct when the querystring in my URL is in lowercase, but when it is in uppercase, the param is not passed, resulting in an incomplete url:
/dosomething/code/


I have tried to add an extra OR-condition with:
- type parameter=CODE

and
Case sensitive: true


But then only the last condition is applied, in this case only the query-param in uppercase is processed correctly.


I have also tried to use an XML rule:

<rule>
    <from>^/dosomething.asp\?(code|CODE)=(.*)$</from>
    <to type="redirect">/dosomething/code/$2</to>
</rule>

but here the question-mark is not recognised as a valid character and the rule is never executed.


Someone any idea how to make this work?


Best regards,
Edwin  


Jasper Floor

unread,
Feb 24, 2016, 11:41:32 AM2/24/16
to Hippo Community
Hi,

i was doing some minor work on this plugin and tried to see if I could reproduce your case. I now suspect a bug wrt the way parameters are processed, or if not a bug at least a non intuitive behavior. I need some more investigation to be sure. Will update when I can.


mvg,
Jsaper

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.

Jeroen Hoffman

unread,
Feb 25, 2016, 4:16:51 AM2/25/16
to hippo-c...@googlegroups.com
Hi Edwin,

How does the rule look in the status page?
Locally that would be http://localhost:8080/site/rewrite-status by default.

Also, redirects (certainly permanent ones) can be cache in browser very
perseveringly so, did you test in incognito/private window?

HTH
Jeroen
> --
> Hippo Community Group: The place for all discussions and announcements about
> Hippo CMS (and HST, repository etc. etc.)
>
> To post to this group, send email to hippo-c...@googlegroups.com
> RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> ---
> You received this message because you are subscribed to the Google Groups "Hippo
> Community" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to hippo-communi...@googlegroups.com
> <mailto:hippo-communi...@googlegroups.com>.

Jasper Floor

unread,
Feb 25, 2016, 5:28:16 AM2/25/16
to Hippo Community
The short answer is what you want isn't possible.

Now the long answer.

So here is what I think is happening. The underlying library (tuckey) tries to match the parameter:

            case TYPE_PARAMETER:
                return evaluateStringCondition(name == null ? null : hsRequest.getParameter(name));

Note that hsRequest.getParameter(name)) is case sensitive. So no matter what you configure the parameter name will always be case sensitive.

So this will either pass null or a string. If the value is null it will eventually:
        if (value == null) {
            // value is null make value ""
            value = "";
        }

it will then:

        StringMatchingMatcher matcher = pattern.matcher(value);

Which, if your pattern is .* will always match.

So basically you will have to add a rule for each permutation of code with upper and lower case.

Is it a bug? Debatable. It certainly is unexpected behavior. At least for me. In any case it perfectly matches the behavior you describe. Also note that it will also evaluate to true even if your parameter is missing. In this case you are looking for "CODE" but giving it "code" it will not find "CODE" and so matches "" to "(.*)" which is true. However, since it couldn't match your parameter it has nothing to put in the query string.

There is little the UrlRewriter can do to avoid this. The only thing would be to rewrite the parameters in the request to be all the same case and then pass that to tuckey. Except you can't set parameters on a request object (well, not without reflection anyway).

mvg,
Jasper

To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.

Edwin B.

unread,
Feb 25, 2016, 7:14:37 AM2/25/16
to Hippo Community
Hi Jasper,

Thanks for your explanation.
I already "fixed" my issue, by creating two basic rules (not advanced rules) with "code" and "CODE", and switched on the parameter "urlrewriter:usequerystring".

Just out of curiosity (I didn't check the source): where is the boolean "Case Sensitive" used in an Advanced Rule?
Here I expected that whatever url, including its querystring parameternames and values (!), would be case insensitive when set to false.
(and then the hsRequest.getParameter(name) itself should do all upper- and lowercase variations of "name".... )

Best regards,
Edwin

Jasper Floor

unread,
Feb 25, 2016, 8:01:28 AM2/25/16
to Hippo Community
Case sensitive is only applied to the path element (domain names are already case insensitive). The query string is not treated this way. The documentation says url but that may not accurate if you see the query string as part of the url.

http://cdn.rawgit.com/paultuckey/urlrewritefilter/master/src/doc/manual/4.0/index.html

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.

Bartosz Oudekerk

unread,
Feb 25, 2016, 9:02:21 AM2/25/16
to Hippo Community
On Thu, 25 Feb 2016 04:14:37 -0800 (PST)
"Edwin B." <ett...@gmail.com> wrote:
> Thanks for your explanation.
> I already "fixed" my issue, by creating two basic rules (not advanced
> rules) with "code" and "CODE", and switched on the parameter
> "urlrewriter:usequerystring".

Please do note, that this is a global parameter, so it will affect (and
thus might break) other existing rules.

You should be able to do it in a single (advanced) rule by writing the
parameter as a regular expression. Perhaps this would even work in a
condition, or have you tried that?

Kind regards,
Bartosz
--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 745 Atlantic Ave, Third Floor, Boston MA 02111

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
http://www.onehippo.com/

Edwin B.

unread,
Feb 25, 2016, 9:32:11 AM2/25/16
to Hippo Community
Hi Bartosz,

Yes, I did realise that it is a global parameter.
Fortunately, we didn't have that many rules.
And the ones that were affected due to the change of this param I did rewrite.

Best regards,
Edwin


Reply all
Reply to author
Forward
0 new messages