symfony2通俗易懂手册
分类:Symfony2
http://blog.csdn.net/jiaochangyun/article/details/7180758
写了好几篇关于twig的东西。。居然还没写个快速入门之类的。现在就写
来源 http://twig.sensiolabs.org/doc/templates.html
概要
twig 的模板就是普通的文本文件,也不需要特别的扩展名,.html .htm .twig 都可以。
模板内的 变量 和 表达式 会在运行的时候被解析替换,标签(tags)会来控制模板的逻辑
下面是个最小型的模板,用来说明一些基础的东西
[html]view plaincopyprint?
- <!DOCTYPE html>
- <html>
- <head>
- <title>My Webpage</title>
- </head>
- <body>
- <ul id=“navigation”>
- {% for item in navigation %}
- <li><a href=“{{ item.href }}”>{{ item.caption }}</a></li>
- {% endfor %}
- </ul>
- <h1>My Webpage</h1>
- {{ a_variable }}
- </body>
- </html>
里面包含两种符号 {% … %} 和 {{ … }} 第一种用来控制的比如for循环什么的,第二个是用来输出变量和表达式的
ide 支持
很多ide 都对twig进行高亮支持。大伙自己找需要的吧。
- Textmate via the Twig bundle
- Vim via the Jinja syntax plugin
- Netbeans via the Twig syntax plugin
- PhpStorm (native as of 2.1)
- Eclipse via the Twig plugin
- Sublime Text via the Twig bundle
- GtkSourceView via the Twig language definition (used by gedit and other projects)
- Coda and SubEthaEdit via the Twig syntax mode
变量
程序会传递给模板若干变量,你需要在模板里输出他们。例如输出 $hello
[html]view plaincopyprint?
- {{ hello }}
如果传递给模板的是对象或者数组,你可以使用点 . 来输出对象的属性或者方法,或者数组的成员。或者你可以使用下标的方式。
[html]view plaincopyprint?
- {{ foo.bar }}
- {{ foo[‘bar’] }}
如果你访问的值不存在就会返回null。TWIG有一整套的流程来确认值是否存在。
for.bar会进行以下操作
。。。如果 foo是个数组,就尝试返回bar成员,如果不存在的话,往下继续
。。。如果foo是个对象,会尝试返回bar属性,如果不存在的话,往下继续
。。。会尝试运行bar方法,如果不存在的话,往下继续
。。。会尝试运行getBar方法,如果不存在的话,往下继续
。。。会尝试运行isBar方法,如果不存在的话,返回null
for[‘bar’] 就简单很多了 for必须是个数组,尝试返回bar成员,如果不就返回null
全局变量
TWIG定义了有一些全局变量
- _self 这个参看macro标签
- _context 这个就是当前的环境
- _charset: 当前的字符编码
变量赋值
具体参见set标签
[html]view plaincopyprint?
- {% set foo = ‘foo’ %}
- {% set foo = [1, 2] %}
- {% set foo = {‘foo': ‘bar’} %}
过滤器 Firters
变量可以被过滤器修饰。过滤器和变量用(|)分割开。过滤器也是可以有参数的。过滤器也可以被多重使用。
下面这例子就使用了两个过滤器。
[html]view plaincopyprint?
- {{ name|striptags|title }}
striptas表示去除html标签,title表示每个单词的首字母大写。更多过滤器参见我博客
过滤器也可以用在代码块中,参见 filter标签
[html]view plaincopyprint?
- {% filter upper %}
- This text becomes uppercase
- {% endfilter %}
函数 Function
这个没什么好说的,会写程序的都知道,TWIG内置了一些函数,参考我的博客
举个例子 返回一个0到3的数组,就使用 range函数
[html]view plaincopyprint?
- {% for i in range(0, 3) %}
- {{ i }},
- {% endfor %}
流程控制
支持for循环 和 if/elseif/else结构。直接看例子吧,没什么好说的。
[html]view plaincopyprint?
- <h1>Members</h1>
- <ul>
- {% for user in users %}
- <li>{{ user.username|e }}</li>
- {% endfor %}
- </ul>
[html]view plaincopyprint?
- {% if users|length > 0 %}
- <ul>
- {% for user in users %}
- <li>{{ user.username|e }}</li>
- {% endfor %}
- </ul>
- {% endif %}
注释
{# … #} 包围的内容会被注释掉,可以是单行 也可以是多行。
载入其他模板
详见include标签(我博客内已经翻译好哦),会返回经过渲染的内容到当前的模板里
[html]view plaincopyprint?
- {% include ‘sidebar.html’ %}
当前模板的变量也会传递到 被include的模板里,在那里面可以直接访问你这个模板的变量。
比如
[html]view plaincopyprint?
- {% for box in boxes %}
- {% include “render_box.html” %}
- {% endfor %}
在 render_box.html 是可以访问 box变量的
加入其他参数可以使被载入的模板只访问部分变量,或者完全访问不到。参考手册
模板继承
TWIG中最有用到功能就是模板继承,他允许你建立一个“骨骼模板”,然后你用不同到block来覆盖父模板中任意到部分。而且使用起来非常到简单。
我们先定义一个基本骨骼页base.html 他包含许多block块,这些都可以被子模板覆盖。
[html]view plaincopyprint?
- <!DOCTYPE html>
- <html>
- <head>
- {% block head %}
- <link rel=“stylesheet” href=“style.css” />
- <title>{% block title %}{% endblock %} – My Webpage</title>
- {% endblock %}
- </head>
- <body>
- <div id=“content”>{% block content %}{% endblock %}</div>
- <div id=“footer”>
- {% block footer %}
- © Copyright 2011 by <a href=“http://domain.invalid/”>you</a>.
- {% endblock %}
- </div>
- </body>
- </html>
我们定义了4个block块,分别是 block head, block title, block content, block footer
注意
1、block是可以嵌套的。
2、block可以设置默认值(中间包围的内容),如果子模板里没有覆盖,那就直接显示默认值。比如block footer ,大部分页面你不需要修改(省力),但你需要到时候仍可以方便到修改(灵活)
下面我看下 子模板应该怎么定义。
[html]view plaincopyprint?
- {% extends “base.html” %}
- {% block title %}Index{% endblock %}
- {% block head %}
- {{ parent() }}
- <style type=“text/css”>
- .important { color: #336699; }
- </style>
- {% endblock %}
- {% block content %}
- <h1>Index</h1>
- <p class=“important”>
- Welcome on my awesome homepage.
- </p>
- {% endblock %}
注意 {% extends “base.html” %} 必须是第一个标签。其中 block footer就没有定义,所以显示父模板中设置的默认值
如果你需要增加一个block的内容,而不是全覆盖,你可以使用 parent函数
[html]view plaincopyprint?
- {% block sidebar %}
- <h3>Table Of Contents</h3>
- …
- {{ parent() }}
- {% endblock %}
extends标签只能有一个,所以你只能有一个父模板,但有种变通到方法来达到重用多个模板到目的,具体参见手册的use标签
HTML转义
主要是帮助转义 尖括号等 <, >, &, ” 可以有两种办法。一种是用标签,另一种是使用过滤器。其实TWIG内部就是调用 php 的htmlspecialchars 函数
[html]view plaincopyprint?
- {{ user.username|e }}
- {{ user.username|e(‘js’) }}
- {% autoescape true %}
- Everything will be automatically escaped in this block
- {% endautoescape %}
因为{{是TWIG的操作符,如果你需要输出两个花括号,最简单到办法就是
[html]view plaincopyprint?
- {{ ‘{{‘ }}
还可以使用 raw 标签和raw 过滤器,详细参考手册
[html]view plaincopyprint?
- {% raw %}
- <ul>
- {% for item in seq %}
- <li>{{ item }}</li>
- {% endfor %}
- </ul>
- {% endraw %}
macros宏
宏有点类似于函数,常用于输出一些html标签。
这里有个简单示例,定义了一个输出input标签的宏。
[html]view plaincopyprint?
- {% macro input(name, value, type, size) %}
- <input type=“{{ type|default(‘text’) }}” name=“{{ name }}” value=“{{ value|e }}” size=“{{ size|default(20) }}” />
- {% endmacro %}
宏参数是没有默认值的,但你可以通过default过滤器来实现。
一般来说宏会定义在其他到页面,然后通过import标签来导入,
[html]view plaincopyprint?
- {% import “forms.html” as forms %}
- <p>{{ forms.input(‘username’) }}</p>
你也可以只导入一个文件中部分宏,你还可以再重命名。
[html]view plaincopyprint?
- {% from ‘forms.html’ import input as input_field, textarea %}
- <dl>
- <dt>Username</dt>
- <dd>{{ input_field(‘username’) }}</dd>
- <dt>Password</dt>
- <dd>{{ input_field(‘password’, type=‘password’) }}</dd>
- </dl>
- <p>{{ textarea(‘comment’) }}</p>
上面的代码表示 从forms.html中导入了 input 和 textarea宏,并给input重命名为input_field。
表达式
TWIG允许你在任何地方使用表达式,他的规则和PHP几乎一模一样,就算你不会PHP 仍然会觉得很简单。
最简单的有
字符串:“hello world” 或者 ‘hello world’
数字:42 或者 42.33
数组:[‘a’,’b’,’c’]
哈希:{‘a':’av’, ‘b':’bv’} 其中keys 可以不要引号 也可以是数字 还可以是一个表达式,比如{a:’av’, b:’bv’} {1:’1v’, 2:’2v’} {1+2:’12v’}
逻辑: true 或者 false
最后还有null
你可以嵌套定义
[html]view plaincopyprint?
- {% set foo = [1, {“foo”: “bar”}] %}
运算符
包括数字运算+ – * / %(求余数) //(整除) **(乘方)
[html]view plaincopyprint?
- <p>{{ 2 * 3 }}=6
- <p>{{ 2 * 3 }}=8
逻辑运算 and or not
比较运算 > < >= <= == !=
包含运算 in 以下的代码会返回 true
[html]view plaincopyprint?
- {{ 1 in [1, 2, 3] }}
- {{ ‘cd’ in ‘abcde’ }}
测试运算 is 这个不用多说 直接看代码
[html]view plaincopyprint?
- {{ name is odd }}
- {% if loop.index is divisibleby(3) %}
- {% if loop.index is not divisibleby(3) %}
- {# is equivalent to #}
- {% if not (loop.index is divisibleby(3)) %}
其他操作符
.. 建立一个指定开始到结束的数组,他是range函数的缩写,具体参看手册
[html]view plaincopyprint?
- <pre name=“code” class=“html”>{% for i in 0..3 %}
- {{ i }},
- {% endfor %}</pre>
- <pre></pre>
| 使用一个过滤器
[html]view plaincopyprint?
- {# output will be HELLO #}
- {{ “hello”|upper }}
~ 强制字符串连接
[html]view plaincopyprint?
- {{ “Hello ” ~ name ~ “!” }}
?: 三元操作符
[html]view plaincopyprint?
- {{ foo ? ‘yes’ : ‘no’ }}
. [] 得到一个对象的属性,比如以下是相等的。
[html]view plaincopyprint?
- {{ foo.bar }}
- {{ foo[‘bar’] }}
你还可以在一个字符串内部插入一个表达式,通常这个表达式是变量。 格式是 #{表达式}
[html]view plaincopyprint?
- {{ “foo #{bar} baz” }}
- {{ “foo #{1 + 2} baz” }}
空白控制
和 php一样,在TWIG模板标签之后的第一个换行符会被自动删掉,其余的空白(包括 空格 tab 换行等)都会被原样输出。
使用spaceless标签就可以删除这些HTML标签之间的空白
[html]view plaincopyprint?
- {% spaceless %}
- <div>
- <strong>foo</strong>
- </div>
- {% endspaceless %}
- {# output will be <div><strong>foo</strong></div> #}
使用-操作符,可以很方便的删除TWIG标签之前或之后与html标签之间的空白。
[html]view plaincopyprint?
- {% set value = ‘no spaces’ %}
- {#- No leading/trailing whitespace -#}
- {%- if true -%}
- {{- value -}}
- {%- endif -%}
- {# output ‘no spaces’ #}
[html]view plaincopyprint?
- {% set value = ‘no spaces’ %}
- <li> {{- value }} </li>
- {# outputs ‘<li>no spaces </li>‘ #}
结束,如果你坚持看到这里,恭喜自己吧,你又多掌握了一些知识,恭喜恭喜
更多0
- 上一篇:ubuntu 给eclipse加到系统菜单
- 下一篇:一个c#的输入框函数
发布于 2014/05/25分类 Symfony2
http://hi.baidu.com/chrisyue/blog/item/6f35b9fb7a76ae2e4e4aea5f.html
让symfony运行在nginx上的完美配置
http://www.ccvita.com/319.html
server {
listen 80; #nginx的端口
server_name www.test.local; #网站网址,这里以localhost为例
root /var/www/test/web; #根目录路径
chareset utf-8;
location /opi/ { #如果url匹配”/sf/”
alias /var/www/test/src/Opi; #访问/sf下面的资源所在的目录
}
location ~ ^/.+\.php(/.*)?$ { #如果匹配类似/frontend_dev.php/*这样的
set $script $fastcgi_script_name; #像/frontend_dev.php这样的url,直接把$fastcgi_script_name赋值给$script
if ($document_uri ~ ^(.+\.php)(/.*)) { #如果又匹配/frontend_dev.php/article/1这样的
set $script $1; #把frontend_dev.php赋值给$script
set $path_info $2; #把/article/1赋值给$path_info,如果用nginx默认的配置,$_SERVER[‘path_info’]会不正确而导致symfony找不到正确的路由
}
fastcgi_pass 127.0.0.1:9000; #php-cgi服务
#下面开始给php的$_SERVER相关变量赋值,不写对都有可能运行不了symfony
include fastcgi_params; #这里面有很多nginx默认给php的$_SERVER赋的环境变量值,
#如果你想要把这句放后面的话,下面已经赋过值的记得注释掉,否则又被覆盖回原来的错误值
fastcgi_param SCRIPT_FILENAME $document_root$script;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param PATH_INFO $path_info;
fastcgi_param DOCUMENT_URI $document_uri;
}
location / { #当前面的规则都不匹配,就运行这个(剩下的url肯定都匹配/)
if (-f $request_filename) { #如果资源(像css,js这样的文件)和请求的url是匹配的,也就是说能根据url直接找到
expires max; #那就永不过期
break; #并且不往下执行了
}
#否则得话都给他rewrite到index.php上去
rewrite .* /index.php last;
}
}
http://www.ccvita.com/319.html
Nginx的Rewrite
经过网上查阅和测试,发现Nginx的Rewrite规则和Apache的Rewite规则差别不是很大,几乎可以直接使用。比如在Apache中这样写规则
rewrite ^/([0-9]{5}).html$ /viewthread.php?tid=$1 last;
而在Nginx中写成这样写是无法启动的,解决的办法是加上两个双引号:
rewrite “^/([0-9]{5}).html$” /viewthread.php?tid=$1 last;
同时将RewriteRule为Rewrite,基本就实现了Nginx的Rewrite规则到Apache的Rewite规则的转换。
Rewrite的Flags
last – 基本上都用这个Flag。
break – 中止Rewirte,不在继续匹配
redirect – 返回临时重定向的HTTP状态302
permanent – 返回永久重定向的HTTP状态301
官方文档请点击这里,另外如果对于302,301这些状态有疑问的,可以参考《301 Redirect 永久重定向的实现》:http://www.ccvita.com/85.html
如果需要对Nginx配置防盗链的话,可以参考《Nginx的防盗链配置》:http://www.ccvita.com/312.html
Discuz!在Nginx下的Rewrite
需要说明的是,下网上以前一直流传的Rewrite都是有误的。
下面的Rewrite中百分号前面多了个转移字符“\”,这在Apache中是需要的,而在Nginx中则是不需要的。
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$
/viewthread.php?tid=$1&extra=page\%3D$3&page=$2 last;
正确的应该是
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$
/viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
这个错误在基本上目前所有使用Nginx作为服务器,并且开启了Rewrite的网站上存在。包括Discuz!官方,目前已经给cnteacher反馈了。
完整正确的Discuz!在Nginx下的Rewrite如下:
rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2
last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$
/viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
break;
http://blog.csdn.net/cnbird2008/article/details/4409620
http://www.cnblogs.com/analyzer/articles/1377684.html
]
本位转自:http://blog.c1gstudio.com/archives/434
推荐参考地址:
Mailing list ARChives 官方讨论区
http://marc.info/?l=nginx
Nginx 常见应用技术指南[Nginx Tips]
http://bbs.linuxtone.org/thread-1685-1-1.html
本日志内容来自互联网和平日使用经验,整理一下方便日后参考。
正则表达式匹配,其中:
- * ~ 为区分大小写匹配
- * ~* 为不区分大小写匹配
- * !~和!~*分别为区分大小写不匹配及不区分大小写不匹配
文件及目录匹配,其中:
- * -f和!-f用来判断是否存在文件
- * -d和!-d用来判断是否存在目录
- * -e和!-e用来判断是否存在文件或目录
- * -x和!-x用来判断文件是否可执行
flag标记有:
- * last 相当于Apache里的[L]标记,表示完成rewrite
- * break 终止匹配, 不再匹配后面的规则
- * redirect 返回302临时重定向 地址栏会显示跳转后的地址
- * permanent 返回301永久重定向 地址栏会显示跳转后的地址
一些可用的全局变量有,可以用做条件判断(待补全)
- $args
- $content_length
- $content_type
- $document_root
- $document_uri
- $host
- $http_user_agent
- $http_cookie
- $limit_rate
- $request_body_file
- $request_method
- $remote_addr
- $remote_port
- $remote_user
- $request_filename
- $request_uri
- $query_string
- $scheme
- $server_protocol
- $server_addr
- $server_name
- $server_port
- $uri
结合QeePHP的例子
- if (!-d $request_filename) {
- rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&controller=$1&action=$2&$3 last;
- rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&controller=$1 last;
- break;
多目录转成参数
abc.domian.com/sort/2 =>
abc.domian.com/index.php?act=sort&name=abc&id=2
- if ($host ~* (.*)/.domain/.com) {
- set $sub_name $1;
- rewrite ^/sort//(/d+)//?$ /index.php?act=sort&cid=$sub_name&id=$1 last;
- }
目录对换
/123456/xxxx -> /xxxx?id=123456
- rewrite ^/(/d+)/(.+)/ /$2?id=$1 last;
例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下:
- if ($http_user_agent ~ MSIE) {
- rewrite ^(.*)$ /nginx-ie/$1 break;
- }
目录自动加“/”
- if (-d $request_filename){
- rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
- }
禁止htaccess
- location ~//.ht {
- deny all;
- }
禁止多个目录
- location ~ ^/(cron|templates)/ {
- deny all;
- break;
- }
禁止以/data开头的文件
可以禁止/data/下多级目录下.log.txt等请求;
- location ~ ^/data {
- deny all;
- }
禁止单个目录
不能禁止.log.txt能请求
- location /searchword/cron/ {
- deny all;
- }
禁止单个文件
- location ~ /data/sql/data.sql {
- deny all;
- }
给favicon.ico和robots.txt设置过期时间;
这里为favicon.ico为99天,robots.txt为7天并不记录404错误日志
- location ~(favicon.ico) {
- log_not_found off;
- expires 99d;
- break;
- }
- location ~(robots.txt) {
- log_not_found off;
- expires 7d;
- break;
- }
设定某个文件的过期时间;这里为600秒,并不记录访问日志
- location ^~ /html/scripts/loadhead_1.js {
- access_log off;
- root /opt/lampp/htdocs/web;
- expires 600;
- break;
- }
文件反盗链并设置过期时间
这里的return 412 为自定义的http状态码,默认为403,方便找出正确的盗链的请求
“rewrite ^/ http://leech.c1gstudio.com/leech.gif;”显示一张防盗链图片
“access_log off;”不记录访问日志,减轻压力
“expires 3d”所有文件3天的浏览器缓存
- location ~* ^.+/.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
- valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194;
- if ($invalid_referer) {
- rewrite ^/ http://leech.c1gstudio.com/leech.gif;
- return 412;
- break;
- }
- access_log off;
- root /opt/lampp/htdocs/web;
- expires 3d;
- break;
- }
只充许固定ip访问网站,并加上密码
- root /opt/htdocs/www;
- allow 208.97.167.194;
- allow 222.33.1.2;
- allow 231.152.49.4;
- deny all;
- auth_basic “C1G_ADMIN”;
- auth_basic_user_file htpasswd;
将多级目录下的文件转成一个文件,增强seo效果
/job-123-456-789.html 指向/job/123/456/789.html
- rewrite ^/job-([0-9]+)-([0-9]+)-([0-9]+)/.html$ /job/$1/$2/jobshow_$3.html last;
将根目录下某个文件夹指向2级目录
如/shanghaijob/ 指向 /area/shanghai/
如果你将last改成permanent,那么浏览器地址栏显是/location/shanghai/
- rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;
上面例子有个问题是访问/shanghai 时将不会匹配
- rewrite ^/([0-9a-z]+)job$ /area/$1/ last;
- rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;
这样/shanghai 也可以访问了,但页面中的相对链接无法使用,
如./list_1.html真实地址是/area/shanghia/list_1.html会变成/list_1.html,导至无法访问。
那我加上自动跳转也是不行咯
(-d $request_filename)它有个条件是必需为真实目录,而我的rewrite不是的,所以没有效果
- if (-d $request_filename){
- rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
- }
知道原因后就好办了,让我手动跳转吧
- rewrite ^/([0-9a-z]+)job$ /$1job/ permanent;
- rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;
文件和目录不存在的时候重定向:
- if (!-e $request_filename) {
- proxy_pass http://127.0.0.1;
- }
域名跳转
- server
- {
- listen 80;
- server_name jump.c1gstudio.com;
- index index.html index.htm index.php;
- root /opt/lampp/htdocs/www;
- rewrite ^/ http://www.c1gstudio.com/;
- access_log off;
- }
多域名转向
- server_name www.c1gstudio.com www.c1gstudio.net;
- index index.html index.htm index.php;
- root /opt/lampp/htdocs;
- if ($host ~ “c1gstudio/.net”) {
- rewrite ^(.*) http://www.c1gstudio.com$1 permanent;
- }
三级域名跳转
- if ($http_host ~* “^(.*)/.i/.c1gstudio/.com$”) {
- rewrite ^(.*) http://top.yingjiesheng.com$1;
- break;
- }
域名镜向
- server
- {
- listen 80;
- server_name mirror.c1gstudio.com;
- index index.html index.htm index.php;
- root /opt/lampp/htdocs/www;
- rewrite ^/(.*) http://www.c1gstudio.com/$1 last;
- access_log off;
- }
某个子目录作镜向
- location ^~ /zhaopinhui {
- rewrite ^.+ http://zph.c1gstudio.com/ last;
- break;
- }
discuz ucenter home (uchome) rewrite
- rewrite ^/(space|network)-(.+)/.html$ /$1.php?rewrite=$2 last;
- rewrite ^/(space|network)/.html$ /$1.php last;
- rewrite ^/([0-9]+)$ /space.php?uid=$1 last;
discuz 7 rewrite
- rewrite ^(.*)/archiver/((fid|tid)-[/w/-]+/.html)$ $1/archiver/index.php?$2 last;
- rewrite ^(.*)/forum-([0-9]+)-([0-9]+)/.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
- rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)/.html$ $1/viewthread.php?tid=$2&extra=page/%3D$4&page=$3 last;
- rewrite ^(.*)/profile-(username|uid)-(.+)/.html$ $1/viewpro.php?$2=$3 last;
- rewrite ^(.*)/space-(username|uid)-(.+)/.html$ $1/space.php?$2=$3 last;
- rewrite ^(.*)/tag-(.+)/.html$ $1/tag.php?name=$2 last;
给discuz某版块单独配置域名
- server_name bbs.c1gstudio.com news.c1gstudio.com;
- location = / {
- if ($http_host ~ news/.c1gstudio.com$) {
- rewrite ^.+ http://news.c1gstudio.com/forum-831-1.html last;
- break;
- }
- }
discuz ucenter 头像 rewrite 优化
- location ^~ /ucenter {
- location ~ .*/.php?$
- {
- #fastcgi_pass unix:/tmp/php-cgi.sock;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fcgi.conf;
- }
- location /ucenter/data/avatar {
- log_not_found off;
- access_log off;
- location ~ /(.*)_big/.jpg$ {
- error_page 404 /ucenter/images/noavatar_big.gif;
- }
- location ~ /(.*)_middle/.jpg$ {
- error_page 404 /ucenter/images/noavatar_middle.gif;
- }
- location ~ /(.*)_small/.jpg$ {
- error_page 404 /ucenter/images/noavatar_small.gif;
- }
- expires 300;
- break;
- }
- }
jspace rewrite
- location ~ .*/.php?$
- {
- #fastcgi_pass unix:/tmp/php-cgi.sock;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fcgi.conf;
- }
- location ~* ^/index.php/
- {
- rewrite ^/index.php/(.*) /index.php?$1 break;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fcgi.conf;
- }

浙公网安备 33010602011771号