nginx seems to treat %3F as "?"

classic Classic list List threaded Threaded
3 messages Options
ST
Reply | Threaded
Open this post in threaded view
|

nginx seems to treat %3F as "?"

ST
Hello,

I have following redirection rule defined:

location ~ "^/(.*)\.html[^\?]+" {
          return 301 /$1.html;
}

so that everything besides "?" after an URL gets truncated:
like
 example.com/test.html%D1%80%D0%BE%D1%80%D0%BB -> example.com/test.html

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

Is it possible somehow?

Thank you!

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: nginx seems to treat %3F as "?"

Francis Daly
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        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
ST
Reply | Threaded
Open this post in threaded view
|

Re: nginx seems to treat %3F as "?"

ST
On Wed, 2017-11-22 at 22:11 +0000, Francis Daly wrote:

> 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

Thank you very much! That was exactly what I needed!

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx