Nginx map module regex in file

Maxim Dounin mdounin at mdounin.ru
Tue Apr 4 13:23:50 UTC 2017


Hello!

On Tue, Apr 04, 2017 at 01:01:19PM +0530, Jagannath Naidu wrote:

> I am trying to redirect some urls to a different document path. My
> configuration file is as follows
> 
> 
> ############ /etc/nginx/conf.d/site.conf ############################
> *map_hash_max_size 2048;*
> *map_hash_bucket_size 128;*
> *map $uri $new {*
> *        include list_4;*
> *}*
> resolver  127.0.0.1;
> server {
>         listen         81;
>         server_name abcexample.com;
>         access_log /var/log/nginx/abcexample-access.log main;
>         error_log  /var/log/nginx/abcexample-error.log;
>         location / {
> *                if ($new) {*
> *                  rewrite ^ $new redirect;*
> *                }*
>               proxy_pass http://127.0.0.1:8000;
>         }
> 
> ################# /etc/nginx/list_4 ##############################
> /abc/1.html /abc/hello;
> /max/1.html /max/;
> ~^/xyz/(?<abc>.*)$ /xyz/123;
> *~^/kkkk/abcdef(?<abc>.*)$ /tttt/bbbbb/jjjj$abc;*
> 
> *~^/kaka/(?<abc>.*)$ /tata/$abc;*
> 
> 
> Note:
> line 1,2 and 3 redirects are working fine.
> But line 4 and 5 are not working.
> 
> 
> *root at Hell1:~# curl -I abcexample.com/kkkk/abcef111.html
> <http://abcexample.com/kkkk/abcef111.html> *
> HTTP/1.1 302 Moved Temporarily
> Server: nginx
> Date: Tue, 04 Apr 2017 07:08:47 GMT
> Content-Type: text/html
> Content-Length: 154
> *Location: http://abcdexample.com/tttt/bbbbb/jjjj$abc
> <http://abcdexample.com/tttt/bbbbb/jjjj$abc>*
> Connection: keep-alive
> 
> My Question is:
> What changes do I have to do in list_4 file to get results as follows
> *Location: http://abcdexample.com/news/bbbbb/jjjj111.html
> <http://abcdexample.com/news/bbbbb/jjjj111.html> *

Check your nginx version.

You are trying to use a combination of text and variables as a 
resulting value of the map.  This is supported only in nginx 
1.11.0+, see http://nginx.org/r/map.

-- 
Maxim Dounin
http://nginx.org/


More information about the nginx mailing list