2017-05-08 73 views
0

這裏是我的nginx.config我應該如何使用nginx中的參數重定向url?

#user nobody; 
worker_processes 1; 

events { 
    worker_connections 1024; 
} 
http { 
    include  mime.types; 
    default_type application/octet-stream; 


    sendfile  on; 
    #tcp_nopush  on; 

    #keepalive_timeout 0; 
    keepalive_timeout 65; 
    server { 
     listen 80; 
     server_name www.example.com; 
     rewrite_log on; 

     location ~^/v1/(\d+)\.html$ { 
     return 301 http://dev-ra.example.com/v1?exid=$1; 
     } 
    } 
} 

編輯注: 我希望這個網址應重定向http://www.example.com/v1/90943.html#featuredhttps://dev-ra.example.com/v1?exid=90943

回答

1

試試這個:

rewrite ^/v1/([0-9]+).html /v1?exid=$1;

PS這個問題已經回答她了ËNGINX - url rewrite regular expression

的PS下面有一個例子,將使用位置塊重定向到不同的領域:

location ~ /v1/([0-9]+) { 
    return 301 http://www.example2.org?exid=$1; 
} 
+0

謝謝emke如果是不同的域名是我必須做的,你可以看到我上面的更新問題,請... – Ramyachinna

+0

您可以簡單地指定域,例如'rewrite ^/v1 /([0-9] +).http http://example1.com/v1?exid = $ 1;' – Emke

+0

嗨..Emke我有試着用你所說的和嘗試過一些可能的解決方案,請參閱我上面編輯的問題,但仍然無法重定向。當我點擊Url http://www.example.com/v1/90943.html#featured時,它仍然保持不變,它不會重定向到https://dev-ra.example.com/v1?exid=90943 – Ramyachinna