当前位置: 首页 > news >正文

泉州鲤城网站建设北京网络seo经理

泉州鲤城网站建设,北京网络seo经理,做直播网站找哪个网站,b2c电子商务的优势有哪些Rewrite主要实现url地址重写,以及重定向,就是把传入web的请求重定向到其他url的过程。 分以下几种场景使用 1、地址跳转,用户访问一个URL,将其定向到另一个URL 2、协议跳转,用户通过http协议请求网站时,…

Rewrite主要实现url地址重写,以及重定向,就是把传入web的请求重定向到其他url的过程。

分以下几种场景使用

1、地址跳转,用户访问一个URL,将其定向到另一个URL

2、协议跳转,用户通过http协议请求网站时,将其重新跳转至https协议方式

3、伪静态,动态页面静态化,为了搜素引擎收录。

4、搜索引擎,SEO优化依赖于url路径,好记的url便于支持搜索引擎录入

Rewrite标记

每个Rewrite后面都有flag标记,主要有以下几种

flag规则
last停止当前匹配,并重新发送请求
barek终止匹配,不发送新请求
redirector临时跳转,关闭nginx请求就不跳转了,302
premanent永久跳转,访问过一次就不会访问原站了,301,第一次请求会保存缓存到浏览器中,通过浏览器缓存跳转

更改配置文件,准备代码文件进行测试last与break

[root@Web01 conf.d]# vim rewrite.conf
server {listen 80;server_name rewrite.koten.com;root /code/rewrite/;location / {rewrite /1.html /2.html;rewrite /2.html /3.html;}location /2.html {rewrite /2.html /a.html;}location /3.html {rewrite /3.html /b.html;
"rewrite.conf" 18L, 343C written 
[root@Web01 conf.d]# systemctl restart nginx
[root@Web01 conf.d]# mkdir -p /code/rewrite
[root@Web01 conf.d]# echo 1.html > /code/rewrite/1.html
[root@Web01 conf.d]# echo 2.html > /code/rewrite/2.html
[root@Web01 conf.d]# echo 3.html > /code/rewrite/3.html
[root@Web01 conf.d]# echo a.html > /code/rewrite/a.html
[root@Web01 conf.d]# echo b.html > /code/rewrite/b.html

发现访问1.html,实际重定向到了b.html 

添加last标记

[root@Web01 conf.d]# vim rewrite.conf
server {listen 80;server_name rewrite.koten.com;root /code/rewrite/;location / {rewrite /1.html /2.html last;rewrite /2.html /3.html;}location /2.html {rewrite /2.html /a.html;}location /3.html {rewrite /3.html /b.html;
"rewrite.conf" 18L, 348C written 
[root@Web01 conf.d]# systemctl restart nginx

 跳过了当前location,进行下一location重定向,最终跳转到a.html

 

添加down标记

[root@Web01 conf.d]# vim rewrite.conf
server {listen 80;server_name rewrite.koten.com;root /code/rewrite/;location / {rewrite /1.html /2.html break;rewrite /2.html /3.html;}location /2.html {rewrite /2.html /a.html;}location /3.html {rewrite /3.html /b.html;
"rewrite.conf" 18L, 349C written 
[root@Web01 conf.d]# systemctl restart nginx

break后不再进行重定向操作,最终定向到2.html 

 redirect与permanent测试

[root@Web01 conf.d]# vim rewrite.conf
server {listen 80;server_name rewrite.koten.com;root /code;location /test {#临时重定向rewrite ^(.*)$  http://www.koten.vip redirect;    #return 302 http://www.koten.vip#永久重定向#rewrite ^(.*)$  http://www.koten.vip permanent;  #return 301 http://www.koten.vip;}
}
~                                                  
~                                                  
"rewrite.conf" 12L, 356C written 
[root@Web01 conf.d]# systemctl restart nginx

 访问rewrite.koten.com/test,定向到www.koten.vip

Rewrite使用案例

我们先开启rewrite日志对规则进行匹配调试

 rewrite_log on;  #加入到/etc/nginx/nginx.conf中

案例1:用户访问/abc/1.html实际上真实访问的是/ccc/bbb/2.html中

[root@Web01 conf.d]# mkdir -p /code/rewrite/ccc/bbb/
[root@Web01 conf.d]# echo '/ccc/bbb/2.html' > /code/rewrite/ccc/bbb/2.html
[root@Web01 conf.d]# vim rewrite.conf
server {listen 80;server_name rewrite.koten.com;root /code/rewrite;location /abc {rewrite (.*) /ccc/bbb/2.html redirect;#return 302 /ccc/bbb/2.html}
}
~                                                  
~                                                  
~                                                  
~                                                  
~                                                  
"rewrite.conf" 10L, 217C written 
[root@Web01 conf.d]# systemctl restart nginx

案例2:用户访问/2018/ccc/bbb/2.html实际上真实访问的是/2023/ccc/bbb.2.html

[root@Web01 conf.d]# mkdir -p /code/rewrite/2023/ccc/bbb/
[root@Web01 conf.d]# echo '/2023/ccc/bbb/2.html' > /code/rewrite/2023/ccc/bbb/2.html
[root@Web01 conf.d]# vim rewrite.conf
server {listen 80;server_name rewrite.koten.com;root /code/rewrite;location /2018 {rewrite ^/2018/(.*) /2023/$1 redirect;}
}
~                                                  
~                                                  
~                                                  
~                                                  
~                                                  
~                                                  
"rewrite.conf" 9L, 188C written  
[root@Web01 conf.d]# systemctl restart nginx

案例3:用户访问/test实际上访问的是https://www.koten.vip

[root@Web01 conf.d]# vim rewrite.conf
server {listen 80;server_name rewrite.koten.com;location /test {rewrite (.*) https://www.koten.vip redirect;}
}
~                                                  
~                                                  
~                                                  
~                                                  
~                                                  
~                                                  
~                                                  
"rewrite.conf" 8L, 154C written
[root@Web01 conf.d]# systemctl restart nginx

案例4:访问course-11-22-33.html实际真实访问/course/11/22/33/course_33.html

[root@Web01 conf.d]# mkdir -p /code/rewrite/course/
11/22/33
[root@Web01 conf.d]# echo '/code/rewrite/course/11/22/33' >
/code/rewrite/course/11/22/33/course_33.html
[root@Web01 conf.d]# vim /etc/nginx/conf.d/rewrite.conf 
server {listen 80;server_name rewrite.koten.com;root /code/rewrite;index index.html;location / {rewrite ^/course-(.*)-(.*)-(.*).html$ /course/$1/$2/$3/course_$3.html redirect;}
}
~                                                  
~                                                  
~                                                  
~                                                  
~                                                  
"rewrite.conf" 10L, 230C written 
[root@Web01 conf.d]# systemctl restart nginx

 案例5:将http请求跳转到https

[root@Web01 conf.d]# vim /etc/nginx/conf.d/rewrite.conf
server {listen 443;server_name rewrite.koten.com;location / {root /code;index index.php index.html;}
}server {listen 80;server_name rewrite.koten.com;rewrite ^(.*) https://$server_name$1 redire
ct;
"rewrite.conf" 17L, 285C written 
[root@Web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@Web01 conf.d]# systemctl restart nginx

案例6:错误页跳转

[root@Web01 rewrite]# cat /etc/nginx/conf.d/rewrite.conf
server {listen 80;server_name rewrite.koten.com;root /code/rewrite;error_page 403 404 500 501 502 @error_test;location @error_test {rewrite ^(.*)$ /404.png break;}
}[root@Web01 rewrite]# systemctl restart nginx

案例7:在跳转的请求行后加上想要的参数&showoffline=1

[root@Web01 rewrite]# vim /etc/nginx/conf.d/rewrite.conf
server {listen 80;server_name rewrite.koten.com;set $args "&showoffline=1";location / {root /code/rewrite;index index.html;}if ($remote_addr = 10.0.0.1 ){rewrite (.*) http://rewrite.koten.com$1;}
}
~                                                  
~                                                  
~                                                  
<rewrite.conf" 13L, 252C written 
[root@Web01 rewrite]# systemctl restart nginx

 

案例8:网站维护,指定IP正常访问,其他IP跳转至维护页面

[root@Web01 rewrite]# vim /etc/nginx/conf.d/rewrite.conf
server {listen 80;server_name rewrite.koten.com;root /code/rewrite;charset utf-8,gbk;location / {index index.html;if ($remote_addr != "10.0.0.2"){rewrite ^(.*)$ /网站维护.jpg break; #如
果来源IP不等于10.0.0.1,则跳转维护页面}}}
<rewrite.conf" 16L, 321C written 
[root@Web01 rewrite]# systemctl restart nginx

Nginx内置参数

$args               #这个变量等于请求行中的参数。
$content_length     #请求头中的Content-length字段。
$content_type       #请求头中的Content-Type字段。
$document_root      #当前请求在root指令中指定的值。
$host               #请求主机头字段,否则为服务器名称。
$http_user_agent    #客户端agent信息
$http_cookie        #客户端cookie信息
$limit_rate         #这个变量可以限制连接速率。
$request_body_file  #客户端请求主体信息的临时文件名。
$request_method     #客户端请求的动作,通常为GET或POST。
$remote_addr        #客户端的IP地址。
$remote_port        #客户端的端口。
$remote_user        #已经经过Auth Basic Module验证的用户名。
$request_filename   #当前请求的文件路径,由root或alias指令与URI请求生成。
$query_string       #与$args相同。
$scheme             #HTTP方法(如http,https)。
$server_protocol    #请求使用的协议,通常是HTTP/1.0或HTTP/1.1。
$server_addr        #服务器地址,在完成一次系统调用后可以确定这个值。
$server_name        #服务器名称。
$server_port        #请求到达服务器的端口号。
$request_uri        #包含请求参数的原始URI,不包含主机名,如:”/foo/bar.php?arg=baz”。
$uri                #不带请求参数的当前URI,$uri不包含主机名,如”/foo/bar.html”。
$document_uri       #与$uri相同。
$X-Forwarded-For:HTTP的请求端真实的IP,只有在通过了HTTP 代理或者负载均衡服务器时才会添加该项。标准格式如下:X-Forwarded-For: client1, proxy1, proxy2

我是koten,10年运维经验,持续分享运维干货,感谢大家的阅读和关注!

http://www.ds6.com.cn/news/109884.html

相关文章:

  • 银行门户网站建设方案营销案例100例简短
  • 公司网站建设推合同成都网站关键词排名
  • 微信网站方案短链接
  • 手机访问网站页面丢失制作一个简单的网站
  • 那个网站可以找人做设计广州网站定制多少钱
  • dreamweaver做动态网站直链平台
  • 龙岗营销网站建设公司网络推广是以企业产品或服务
  • 小型营销企业网站建设策划2023年6月份疫情严重吗
  • 做海报哪个网站好seo一键优化
  • 如何做贷款网站推广网页搜索优化seo
  • wordpress pc360优化大师官方免费下载
  • 网站建设方案 评价深圳优化排名公司
  • 注册一个公司一年费用深圳最好seo
  • 自己制作二维码的软件提升seo排名
  • 电商网站建设注意事项营销培训机构哪家最专业
  • 广州网络科技有限公司有哪些关键词优化排名
  • 有域名如何做网站推广之家官网
  • 香港网站建设公司最彻底的手机优化软件
  • 哪里可以学做网站营销推广方案范文
  • 查注册公司什么网站深圳英文网站推广
  • 贵州软件定制优化服务
  • 网站打开时的客户引导页做网站公司哪家好
  • 河间做网站荥阳seo
  • 个人做网站的流程万能的搜索引擎
  • 广州网站建设360元曲靖seo
  • 长沙做企业网站上海有哪些优化网站推广公司
  • 常州做网站信息免费软文网站
  • 蔡甸网站建设域名注册购买
  • 电子科技产品东莞网站建设推广方式有哪几种
  • 网站建设 接单百度关键词排名用什么软件