Couchcms的Nginx伪静态实现


location / {
       # existing rules
        ..
        ..
        ###### Couch templates start #####
        if (!-e $request_filename) {
            #services.php
            rewrite ^/services$ /services/ permanent;
            rewrite ^/services/$ /services.php last;
            rewrite ^/services/.*?([^\.\/]*)\.html$ /services.php?pname=$1 last;
            rewrite "^/services/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$" /services.php?d=$1$2$3 last;
            rewrite ^/services/[^\.]*?([^/\.]*)/?$ /services.php?fname=$1 last;

            #portfolio.php
            rewrite ^/portfolio$ /portfolio/ permanent;
            rewrite ^/portfolio/$ /portfolio.php last;
            rewrite ^/portfolio/.*?([^\.\/]*)\.html$ /portfolio.php?pname=$1 last;
            rewrite "^/portfolio/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$" /portfolio.php?d=$1$2$3 last;
            rewrite ^/portfolio/[^\.]*?([^/\.]*)/?$ /portfolio.php?fname=$1 last;
           
            #blog.php
            rewrite ^/blog$ /blog/ permanent;
            rewrite ^/blog/$ /blog.php last;
            rewrite ^/blog/.*?([^\.\/]*)\.html$ /blog.php?pname=$1 last;
            rewrite "^/blog/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$" /blog.php?d=$1$2$3 last;
            rewrite ^/blog/[^\.]*?([^/\.]*)/?$ /blog.php?fname=$1 last;

            #index.php
            rewrite ^/.*?([^\.\/]*).html$ /?pname=$1 last;
            rewrite "^/([1-2]d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$" /?d=$1$2$3 last;
            rewrite ^/[^\.]*?([^/\.]*)/$ /?fname=$1 last;
        }
        ####End Couch templates ######
    }
    ..
    ..
}