首页 > Other > apache rewrite转nginx经验

apache rewrite转nginx经验

在nginx中这样写规则

rewrite ^/([0-9]{5}).html$ /x.jsp?id=$1 last;

是无法启动的,解决的办法是加上两个双引号

rewrite “^/([0-9]{5}).html$” /x.jsp?id=$1 last;

这样就OK了,应该可以说是完全兼容apache的语法的,只需要改下RewriteRule为Rewrite,后面的一般可以这样对应改

[R] -> redirect;
[P] -> last;
[R,L] -> redirect;
[P,L] -> last;
[PT,L] -> last;

nginx rewrite中支持4种类型的转向:

跳转型的
redirect:302跳转到rewrite后的地址
permanent:301永久定向到rewrite后的地址,对搜索引擎更友好

代理型的
last:重新将rewrite后的地址在server标签中执行
break:将rewrite后的地址在当前location标签中执行

分类:Other
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: