nginx seems to treat %3F as "?"
Francis Daly
francis at daoine.org
Wed Nov 22 22:11:30 UTC 2017
On Wed, Nov 22, 2017 at 05:34:13PM +0200, ST wrote:
Hi there,
> I have following redirection rule defined:
>
> location ~ "^/(.*)\.html[^\?]+" {
That says: /anything.html followed by one-or-more things that are not ?.
Note that "location" works on the unencoded url version, and does not
include the ? that marks the query string, or anything after it.
> return 301 /$1.html;
> }
>
> so that everything besides "?" after an URL gets truncated:
No.
*everything* after .html gets removed in the 301 response, provided
that there is something immediately after .html that is not a ? (which
would be %3F in the original url, because ? is special).
> like
> example.com/test.html%D1%80%D0%BE%D1%80%D0%BB -> example.com/test.html
The thing immediately after .html is the unencoded version of %D1, which is
not ?, so the location matches and the rewrite happens.
> however it doesn't work when "?" is url encoded into %3F. I would like
> example.com/test.html%3F to redirect to example.com/test.html
Your location block explicitly excludes that case.
Why?
As in: I do not understand what the thing that you are trying to achieve
is. Can you explain it? Perhaps with examples of some things that should
be rewritten and some things that should not be?
At a guess, perhaps
location ~ ^/(.*)\.html. {
is what you want? Starts with /, includes .html, and is followed by anything.
That should match /a.htmlx and /a.html%3Fx, but not /a.html or /a.html?x=y
f
--
Francis Daly francis at daoine.org
More information about the nginx
mailing list