[root@slave logs]# cat ../conf/vhosts/test.com.conf #test.com.conf 配置文件
server
{
listen 80;
server_name test.com www.test.com; #服务器的基本名称,多域名用空格隔开
root /data/web;
access_log logs/test.com.access.log;
if ($host != 'www.test.com') #if指令 用于条件判断
{
rewrite ^/(.*) http://www.test.com/$1 permanent; #注意这里 访问test.com 301重定向到 www.test.com
}
#rewrite ^/bbs/(.*) http://bbs.test.com/$1 permanent; #此处注释将在下面使用
location /
{
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location =/50x.html
{
root html;
}
location ~* \.php$
{
root /data/web;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/web$fastcgi_script_name;
include fastcgi_params;
}
} 单页面301重定向: 把http://example.com/tags.php?para=xxx 重定向到 http://example.com/tags 若按照默认的写法:rewrite ^/tags.php(.*) /tags permanent; 重定向后的结果是:http://example.com/tags?para=xxx 如果改写成:rewrite ^/tags.php(.*) /tags? permanent; 那结果就是:http://example.com/tags 所以,关键点就在于“?”这个尾缀。假如又想保留某个特定的参数,那又该如何呢?可以利用Nginx本身就带有的$arg_PARAMETER参数来实现。 例如: 把http://example.com/tags.php?para=xxx&p=xx 重写向到 http://example.com/tags?p=xx 可以写成:rewrite ^/tags.php /tags?p=$arg_p? permanent; 只求结果的朋友可以直接忽略前面的内容,看这里: rewrite ^/tags.php /tags permanent; //重写向带参数的地址 rewrite ^/tags.php /tags? permanent; //重定向后不带参数 rewrite ^/tags.php /tags?id=$arg_id? permanent; //重定向后带指定的参数
少长咸集
-
上一篇
站长和SEOer眼中的360搜索到底什么样?
发表于2014-05-26 浏览214 评论0
-
下一篇
nginx rewrite 参数和例子
发表于2014-06-03 浏览208 评论0
-
服务器反爬虫攻略:nginx禁止某些User Agent抓取网站
浏览219 评论0
Nginx
seo
spider
-
Nginx目录后自动加斜杠的方法
浏览220 评论0
Nginx
-
nginx中使用rewrite模块的参数及示例
浏览221 评论0
Nginx
nginx伪静态
-
fail2ban读取nginx日志禁止非法ip访问
浏览207 评论0
Nginx
fail2ban
-
nginx rewrite 参数和例子
浏览208 评论0
Nginx