nginx dynamic url rewrite

作者: 2hei 发表于2010年8月 6日 19:48
版权声明: 可以转载, 转载时务必以超链形式标明文章原始出处和作者信息及版权声明
http://www.2hei.net/mt/2010/08/nginx-dynamic-url-rewrite.html

I have such a request, will rewrite url to google's search site,
type http://mysite/search/search.html?t=laday gaga --> http://www.google.com/search?q=lady%20gaga
I donn't want to use other tools(php/java etc.) except nginx.
For a long time googleing, finally find how to setting nginx dynamic url rewrite :)

 location /search/ {
  root   /var/2hei.net/nginx;
  if ($args){
  rewrite ^/search/search.html "http://www.google.com/search?q=$arg_t?" last;
  }
 }

and '?' is very important, or the rewrite url will add append query string,
http://mysite/search/search.html?t=laday gaga --> http://www.google.com/search?q=lady%20gaga?t=lady%20gaga
we will get wrong rewrite url.
alse we can use $query_string
 if ($query_string ~* t=(.*)){
  ...
 }


Just enjoy it!

| | Comments (1) | TrackBacks (0)

1 Comments

fenderbirds 说:

nice article, keep the posts coming

发表一个评论

关于这篇文章

这篇文章由2hei2010年8月 6日 19:48发布.

上一篇:Get memcached all items and deleted them if needed.

下一篇:a script of awk array - just mark

回到首页 或者查看归档文章

  • Powered by FeedBurner
  • Add to Google Reader or Homepage
  • Add to My AOL
  • Subscribe in NewsGator Online
  • del.icio.us/2heidel.icio.us/2hei
  • Subscribe to feed feeds