如何使用nginx中的参数重定向url

时间:2016-07-22 04:01:24

标签: redirect nginx url-rewriting

例如,我想从https://www.example.com/ $ {pid} .txt重定向到http://www.anotherExample.com/api?pid= $ {pid} 如何在nginx中配置它? 在此先感谢:)

2 个答案:

答案 0 :(得分:1)

试试这个:

server {

  listen 443;
  server_name www.example.com;

  location ~* ^/(.+)\.txt$ {
    return 301 http://www.anotherexample.com/api?pid=$1;
  }

}

如果您的pid具有特定格式(例如仅限数字),请使用适当的模式替换(.+)

如果您想在不重定向的情况下显示内容,请将return 301替换为proxy_pass

答案 1 :(得分:0)

最好的方法是使用return 301 $scheme://www.anotherexample.com/api?pid=$1;,它会将请求重定向到您设置的网站,也许最好制作<span class="taLnk hvrIE6 tr395770395 moreLink ulBlueLinks" onclick=" var options = { flow: 'CORE_COMBINED', pid: 39415, onSuccess: function() { ta.util.cookie.setPIDCookie(2247); ta.call('ta.servlet.Reviews.expandReviews', {type: 'dummy'}, ta.id('review_395770395'), 'review_395770395', '1', 2247);; window.location.hash = 'review_395770395'; } }; ta.call('ta.registration.RegOverlay.show', {type: 'dummy'}, ta.id('review_395770395'), options); return false; "> More&nbsp; </span> ,这样您的网址就会被重定向为购买并安装SSL时使用HTTPS

相关问题