Nginx实现pathinfo模式配置详解

版权声明:转载请标明出处! https://blog.csdn.net/weixin_38642130/article/details/86751074

什么是pathinfo模式呢?

pathinfo是伪静态的一种,我们先解释一下伪静态的概念,伪静态页面是静态URL与动态URL互通的一个桥梁,它是指动态网址通过URL重写的手段去掉其动态参数,使URL静态化,但在实际的网页目录中并没有重写URL。
简单来说,伪静态URL就是通过服务器转换伪装文件名或地址,使该页面类似于静态页面,但服务器上没有独立存在的文件,其本质还是动态页面。

使用过 ThinkPHP 框架开发应用的同学应该都会知道,它有一种 URL 模式就是 pathinfo,看起来类似下面的 URL:
http://example.com/module/controller/action/key1/value1/key2/value2.html
其实上面的 URL 是被重写过的,它的原型是下面的样子:
http://example.com/index.php?m=module&c=controller&a=action&key1=value1&key2=value2

被重写过后的URL有如下几大好处:

  1. 它提供了最好的SEO支持
  2. 可以实现 URL 的伪静态
  3. 它看起来更简洁、更好看

参考配置

server
{
    listen 443 ssl;
    server_name  www.wege.com;
    index index.php index.html;
    access_log /usr/local/nginx/logs/access_nginx.log;

    set $root /web/wege.com;

    ssl_certificate /root/ssl/1_www.wege.com_bundle.crt;
    ssl_certificate_key /root/ssl/2_www.wege.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    location ~ \.php {
        fastcgi_pass	127.0.0.1:9000;
        fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param    SCRIPT_FILENAME    $root$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
    {
    	expires		30d;
     	access_log	off;
        root		$root;
    }
    location ~ ^(.*)/.svn/{
        deny all;
    }
    location / {
        root    $root;
        index    index.html index.php;
        if ( -f $request_filename) {
            break;
        }
        if ( !-e $request_filename) {
            rewrite ^(.*)$ /index.php/$1 last;
            break;
        }
    }  
}

猜你喜欢

转载自blog.csdn.net/weixin_38642130/article/details/86751074
今日推荐