pvdung / urlrewritefilter

Automatically exported from code.google.com/p/urlrewritefilter
Other
0 stars 0 forks source link

Appending query strings breaks URL #116

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a rewrite rule like the one below:
    <rule>
        <from>^/robots\.txt$</from>
        <to type="permanent-redirect" last="true" qsappend="true">/en/robots.txt</to>
    </rule>

2. Go to a URL which will be rewritten with the above rule, and make sure to 
use a query-string
    www.mydomain.com/robots.txt?param1=value1&param2=value2

3. Check the rewritten URL

After the rewrite we would expect to see the following URL:
    www.mydomain.com/en/robots.txt?param1=value1&param2=value2
but the "?" before the first parameter has been replaced with a "&"
    www.mydomain.com/en/robots.txt&param1=value1&param2=value2

We are using version 4.0.3 and tested on several operating systems.

Currently we fixed it ourselves by changing the code:

Class: NormalRule.java
Method: public RewrittenUrl matches(final String url, final HttpServletRequest 
hsRequest, final HttpServletResponse hsResponse, RuleChain chain) ...

Original line of code (line 99)
    ruleExecutionOutput.setReplacedUrl(target + "&" + hsRequest.getQueryString());

New code
    if (target.contains("?")) {
        ruleExecutionOutput.setReplacedUrl(target + "&" + hsRequest.getQueryString());
    } else {
        ruleExecutionOutput.setReplacedUrl(target + "?" + hsRequest.getQueryString());
    }

Original issue reported on code.google.com by david.va...@gmail.com on 25 Jul 2012 at 11:57

Attachments:

GoogleCodeExporter commented 9 years ago
I'm seeing the same thing...

This works:
<to type="redirect" last="true">http://localhost:8080/$2?%{query-string}</to>
While this does not:
<to type="redirect" qsappend="true" last="true">http://localhost:8080/$2</to>

This looked like a great feature and was actually the reason I upgraded from 
v3.2.

Also, I'd love to see this option work so that it only appends '?' when there 
is a query string to append.  This would help me clean up my rules that are 
duplicated just for this reason.

Original comment by raymond....@gmail.com on 30 Jul 2012 at 12:39

GoogleCodeExporter commented 9 years ago
Fixed in trunk please verify.

Original comment by p...@tuckey.org on 31 Jul 2012 at 3:58

GoogleCodeExporter commented 9 years ago
Checked it, seems to be ok now!

Thanks for the quick fix!

Original comment by david.va...@gmail.com on 31 Jul 2012 at 7:27

GoogleCodeExporter commented 9 years ago
Hi, any chance of seeing this issue in a release available via Maven Central? 
We're using some ugly workarounds right now w/ 4.0.4, and I'd love to see them 
go away...

Original comment by bengunnink on 19 Nov 2012 at 3:02

GoogleCodeExporter commented 9 years ago
Greetings.

I'm using 4.0.4. version and I have exact problem - urlrewritefilter replaces ? 
with & . Is there any chance to make new version with that fix?

Many thanks.

Original comment by mario.ec...@gmail.com on 3 Apr 2014 at 2:29

GoogleCodeExporter commented 9 years ago
Hi, all. The fix has not been released with 4.0.4. It is in trunk, but not in 
4.0.4 release. Release is needed.

Original comment by YLepik...@gmail.com on 14 May 2014 at 12:59

GoogleCodeExporter commented 9 years ago
Two years later, still waiting for a new release fixing this issue... Is 
UrlRewriteFilter abandoned?

Original comment by christop...@gmail.com on 6 Aug 2014 at 3:56