您的位置:首页 > 运维架构 > Nginx

textpattern 在 nginx 上的 rewrite 规则

2012-07-31 08:34 405 查看
Clean URLs for Textpattern with Nginx
最近又开始折腾 textpattern ,由于我的 web 环境是基于 nginx ,在网上搜索了下 textpattern 在 nginx 上的 rewrite 规则,找到一个最完美的,

适用 textpattern 的各种链接形式
Reference Address:

http://motionobj.com/blog/textpattern-on-nginx-rewrite-rule

代码如下

[code] location /
[code] { root /var/www/where-document-root-is/; index index.html index.htm index.php;
[code] if (!-e $request_filename) { rewrite ^(.*) /index.php; } }
另外提供几个非完美的
[code] if (-e $request_filename) { break; } rewrite ^/(.*)$ /index.php?=$1 last;
[code] ---------------
[code] rewrite ^(.*)/category/(.*)/$ $1/index.php?c=$2 last;#
rewrite ^(.*)/category/(.*)$ $1/index.php?c=$2 last;
rewrite ^(.*)/rss/$ $1/index.php?rss=1 last;
rewrite ^(.*)/atom/$ $1/index.php?atom=1 last;
rewrite ^(.*)/tag/(.*)/$ $1/index.php?s=tag&t=$2 last;#
rewrite ^(.*)/tag/(.*)$ $1/index.php?s=tag&t=$2 last;
rewrite ^(.*)/(\d*)(/.*)$ $1/index.php?id=$2 last;
rewrite ^(.*)/(.*)/$ $1/index.php?s=$2 last;
rewrite ^(.*)/(.*)$ $1/index.php?s=$2 last;
[code] -----------------
最上面的是最完美解决方案,
下面两种只支持某个特定格式,具体如果从代码上看不出来,您可以直接尝试一下就知道了。

__EOF__

Be Sociable, Share!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: