Welcome! Log In Create A New Profile

Advanced

Re: Regular Expression global redirect

António P. P. Almeida
February 26, 2012 09:40AM
On 26 Fev 2012 07h19 CET, edho@myconan.net wrote:

> 2012/2/26 António P. P. Almeida <appa@perusio.net>:
>> server {
>>    server_name ^~www\.(?<domain>.*)$;
>>    return 301 http://$domain;
>> }
>>
>
> Where can I read the documentation for this? It doesn't seem to be
> mentioned in nginx.org docs and nginx wiki

AFAIK it's undocumented. You can use return for a lot of things. I
hardly ever use rewrite anymore. There are situations where it still
applies, but they're not the majority.

IMHO using return is more Nginx like, while rewrite harks back to
Apache's mod_rewrite and its "reverse" logic.

Using return you can make a poorman's web service, for example:

location /ws-test {
return 200 "{uri: $uri, 'service name': 'this is a service'}\n";
}

If you do a capture in the location you can use the captures in the
URI you give return as the second argument. The default status is
302. AFAIK it doesn't support named locations redirects. Hence the
usual idiom of returning an error status and then using error_page for
the redirect with a named location.

It was late and I forgot the $request_uri :(

Also for old PCRE versions the ?<name> has to be replaced by ?P<name>.

Both things that were already addressed in the thread.

--- appa

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

Regular Expression global redirect

altiamge February 25, 2012 10:59PM

Re: Regular Expression global redirect

António P. P. Almeida February 25, 2012 11:42PM

Re: Regular Expression global redirect

Edho Arief February 26, 2012 01:22AM

Re: Regular Expression global redirect

António P. P. Almeida February 26, 2012 09:40AM

Re: Regular Expression global redirect

Edho Arief February 26, 2012 09:44AM

Re: Regular Expression global redirect

altiamge February 26, 2012 02:27AM

Re: Regular Expression global redirect

altiamge February 26, 2012 06:39PM

Re: Regular Expression global redirect

Edho Arief February 26, 2012 02:30AM

Re: Regular Expression global redirect

António P. P. Almeida February 26, 2012 07:22PM

Re: Regular Expression global redirect

altiamge February 26, 2012 07:26PM

Re: Regular Expression global redirect

altiamge February 26, 2012 08:15PM

Re: Regular Expression global redirect

António P. P. Almeida February 26, 2012 07:42PM

Re[2]: Regular Expression global redirect

Max February 27, 2012 01:34AM

Re: Re[2]: Regular Expression global redirect

António P. P. Almeida February 27, 2012 05:14AM

Re[4]: Regular Expression global redirect

Max February 27, 2012 10:48PM

Re: Re[4]: Regular Expression global redirect

António P. P. Almeida February 28, 2012 07:12AM

Re: Regular Expression global redirect

Edho Arief February 26, 2012 01:12AM

Re: Regular Expression global redirect

Mark Alan February 26, 2012 07:20AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 252
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