Welcome! Log In Create A New Profile

Advanced

Re: Rewrite regex with percent signs

Francis Daly
May 22, 2016 09:44AM
On Sun, May 22, 2016 at 07:16:35AM -0400, redrobes wrote:

Hi there,

> For example, we have a url of the following:
> /members/redrobes-albums-2d%20vs%203d%20?-picture12345-mt-pub01.jpg

The %20 pieces in there are url-encoded spaces. In a "location" or a
"rewrite", you would have to match a single space character each.

However, there is also a ? in the url; that marks the start of the query
string. A "location" or "rewrite" in nginx will *not* consider that part
of the url.

> it needs to go to
>
> /attachment.php?attachmentid=12345

It is not immediately clear to me which parts of the original url are
important in deciding whether the request should be redirected or not.

> we have:
>
> location /members/ {
> rewrite ^/members/.+-albums-.+-picture(\d+)-.*
> /attachment.php?attachmentid=$1? redirect;
> }

That suggests that just those three words matter. You might be able
to put something together involving "$args" matching "-picture(\d+)-"
if the request matches "^/members/.*-albums-", perhaps?

Alternatively, perhaps the thing that created the url in the first place,
incorrectly did not url-encode the ? to %3F.

> and this particular one is not working. It works with many others where the
> original url did not have the %20's in them. So there is something about
> those %20's that are causing these to fail.

I suspect that it is the ? rather than the %20, from the one example
you have given.

> I can write a perl script and run that url through its regex and it does
> change them.
>
> So what does the nginx regex do different from perl regex with regard to %
> signs.

With regard to % signs, nginx regex uses the %-unencoded version. With
regard to ?, some nginx parts do not consider anything after the ? when
matching.

Good luck with it,

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Rewrite regex with percent signs

redrobes May 22, 2016 07:16AM

Re: Rewrite regex with percent signs

Francis Daly May 22, 2016 09:44AM

Re: Rewrite regex with percent signs

redrobes May 22, 2016 01:18PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 300
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready