Clean URLs for Textpattern with Nginx
最近又开始折腾 textpattern ,由于我的 web 环境是基于 nginx ,在网上搜索了下 textpattern 在 nginx 上的 rewrite 规则,找到一个最完美的,
适用 textpattern 的各种链接形式
Reference Address:
http://motionobj.com/blog/textpattern-on-nginx-rewrite-rule
代码如下
location /
{ root /var/www/where-document-root-is/; index index.html index.htm index.php;
if (!-e $request_filename) { rewrite ^(.*) /index.php; } }
另外提供几个非完美的
if (-e $request_filename) { break; } rewrite ^/(.*)$ /index.php?=$1 last;
---------------
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;
-----------------
最上面的是最完美解决方案,
下面两种只支持某个特定格式,具体如果从代码上看不出来,您可以直接尝试一下就知道了。
__EOF__
Be Sociable, Share!