nginx rewrite重写规则简明笔记

nginx rewrite重写规则简明笔记

比方说http://newmiracle.cn/?p=888
我要改成能这个访问http://newmiracle.cn/p888/

首先用正则获取888 ^p([0-9]*)/$
然后
<pre>
location / {
root /home/www/wordpress;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/p([0-9]*)/$ /?p=$1 last;
#rewrite /index.html /?p=967 redirect;
break;
}
}
</pre>
注意最前面的/必须要加上 不然报错
调试方法 可以把last改成 redirect 重定向跳转
1 如果没跳转所以根本没有匹配到
2 还有就是跳转了没跳转到正确路径

调整好了 再改成last

猜你喜欢

转载自www.cnblogs.com/newmiracle/p/11875979.html