谈谈apache的htaccess伪静态规则转到nginx

上文讲了htaccess转iis的httpd.ini伪静态规则

下面再谈谈如何把apache的htaccess规则转到nginx下!

简单举个例子,如apache下的这样一条伪静态规则

RewriteRule  ^/([0-9]+)/?$ index.php?s=content/index/loupan&t=zhuye&catid=14&id=$1 [L]
RewriteRule  ^/index.html?$ index.php?s=content/index/loupan&t=zhuye&catid=14&id=$1 [L]
转换到nginx下后为下面这样,其实改动还是很小的!

location / {
rewrite  ^/([0-9]+)/?$ /index.php?s=content/index/loupan&t=zhuye&catid=14&id=$1 last;
rewrite  ^/index\.html$ /index.php?s=content/index/loupan&t=zhuye&catid=14&id=$1 last;
}

但是apache下的RewriteCond写法,在nginx下是不认的,这个改动比较大!

RewriteCond  %{QUERY_STRING}  keyword=(.*)
RewriteRule  ^/list.html(.*)  index.php?s=content/index/lists&catid=14&keyword=%1 [L]

if ($query_string ~ ^keyword=(.*)$) {
   set $id_tmp $1;
   rewrite "^/list.html$"  index.php?s=content/index/lists&catid=14&keyword=$id_tmp permanent;
}

一定要注意上面if后面是有个空格的!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值