Welcome! Log In Create A New Profile

Advanced

I hav

Posted by Patschi 
I hav
October 27, 2011 05:33AM
Hi nginx-Fans,

I have a little problem with my rewrite-lines with nginx.
I tried about 1 hour to fix it, but it still won't work.

I currently have this lines:
[quote]
rewrite ^/encode?(.*)(&[1-9]+)$ /encode.php?q=$1&s=$2 last;
rewrite ^/decode?(.*)$ /decode.php?q=$1 last;
[/quote]

Encode example:
[quote]http://LINK/encode?HERE_GOES_THE_DATA_MAYBE_A_LINK&5[/quote]

Decode example:
[quote]http://LINK/decode?LINK[/quote]

I think nginx won't accept the questionmark in the rewrite rule.
When I open the Link it says "404 Not found". If I try
[quote]http://LINK/encodeDATA[/quote]
it works...

Somebody has a solution?

Thank you!

Greets,
Patschi
Re: I hav
October 27, 2011 07:27AM
Hi,

[quote]
rewrite ^/encode?(.*)(&[1-9]+)$ /encode.php?q=$1&s=$2 last;
rewrite ^/decode?(.*)$ /decode.php?q=$1 last;
[/quote]

It's a bad idea, because: 1) you are forced to use "rewrite"s and "if"s; and 2) your links that you specify as an argument to encode/decode may contain query parameters, and they would mix with q= & s= parameters during the rewrite. but ok:

if ($request_uri ~ ^/encode\?(?<link>[^&]+)&(?<enc_args>\d+)$) {
rewrite ^ /encode.php?q=$link&s=$enc_args? last;
}

if ($request_uri ~ ^/decode\?(?<link>.+)$) {
rewrite ^ /decode.php?q=$link? last;
}

Andrejs
Re: I hav
October 27, 2011 08:18AM
Thank you very much.
I'll try it when I am at home.

What do you exactly mean with 2)?

Greets,
Patschi
Re: I hav
October 27, 2011 12:18PM
I tested it now and it works perfectly.
Thank you very much!
Re: I hav
October 27, 2011 01:33PM
Patschi Wrote:
-------------------------------------------------------

> What do you exactly mean with 2)?


When the link argument of the URL itself contains query string arguments like:

http://yourserver/encode?http://test.com/?arg1=val1&arg2=val2&5

You might have a hard time parsing/getting the link itself (http://test.com/?arg1=val1&arg2=val2, that is).

Andrejs
Re: I hav
October 27, 2011 03:32PM
Ah, okay.

And how I can fix that?

Greets,
Patschi
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 125
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready