nginx 伪静态 重定向 包括域名、目录、文件等方法_nginx文件目录

2020-02-26 其他范文 下载本文

nginx 伪静态 重定向 包括域名、目录、文件等方法由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“nginx文件目录”。

nginx 伪静态 重定向 包括域名、目录、文件等方法

在网站建设中需要网页重定向的情况很多:如网页目录结构变动,网页重命名、网页的扩展名改变、网站域名改变等。如果不做重定向,用户的收藏和搜索引擎数据库中的旧地址只能让访客得到一个404错误信息页面,访问流量白白丧失。不仅如此,之前该页面的一切积累(比如PR值)就都白费了。

301重定向不仅能使页面实现自动跳转,对于搜索引擎来说,也可能可以传递PR值

1、将多个域名指向同一web目录:

server_name

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_pa http://127.0.0.1/;

}

域名跳转

server

{

listen 80;

server_name jump.c1gstudio.com;

index index.html index.htm index.php;

root /opt/lampp/htdocs/$ /$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/ last;

break;

}

}

discuz ucenter 头像 rewrite 优化

location ^~ /ucenter {

location ~.*.php?$

{

#fastcgi_pa unix:/tmp/php-cgi.sock;

fastcgi_pa 127.0.0.1:9000;

fastcgi_index index.php;

include fcgi.conf;

}

location /ucenter/data/avatar {

log_not_found off;

acce_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_pa unix:/tmp/php-cgi.sock;

fastcgi_pa 127.0.0.1:9000;

fastcgi_index index.php;

include fcgi.conf;

}

location ~* ^/index.php/

{

rewrite ^/index.php/(.*)/index.php?$1 break;

fastcgi_pa 127.0.0.1:9000;

fastcgi_index index.php;

include fcgi.conf;

}

《nginx 伪静态 重定向 包括域名、目录、文件等方法.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
nginx 伪静态 重定向 包括域名、目录、文件等方法
点击下载文档
相关专题 nginx文件目录 静态 重定向 域名 nginx文件目录 静态 重定向 域名
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文