小贝博客

主机资讯以及工具软件分享

typecho设置伪静态

location /typecho/ {
    if (!-e $request_filename) {
        rewrite ^(.*)$ /typecho/index.php$1 last;
    }
}

还有一种办法如下

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

当用户请求 http://localhost/example 时,这里的 $uri 就是 /example。
try_files 会到硬盘里尝试找这个文件。
如果存在名为 /$root/example(其中 $root 是项目代码安装目录)的文件,
就直接把这个文件的内容发送给用户。
显然,目录中没有叫 example 的文件。
然后就看 $uri/,增加了一个 /,也就是看有没有名为 /$root/example/ 的目录。
又找不到,就会 fall back 到 try_files 的最后一个选项 /index.php,
发起一个内部 “子请求”,也就是相当于 nginx 发起一个 HTTP 请求到 http://localhost/index.php

-->

除了在后台设置上以后,nginx要单独设置
在网上看到的办法,都是如下设置

location /typecho/ {
    if (!-e $request_filename) {
        rewrite ^(.*)$ /typecho/index.php$1 last;
    }
}

还有一种办法如下

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

当用户请求 http://localhost/example 时,这里的 $uri 就是 /example。
try_files 会到硬盘里尝试找这个文件。
如果存在名为 /$root/example(其中 $root 是项目代码安装目录)的文件,
就直接把这个文件的内容发送给用户。
显然,目录中没有叫 example 的文件。
然后就看 $uri/,增加了一个 /,也就是看有没有名为 /$root/example/ 的目录。
又找不到,就会 fall back 到 try_files 的最后一个选项 /index.php,
发起一个内部 “子请求”,也就是相当于 nginx 发起一个 HTTP 请求到 http://localhost/index.php

本原创文章未经允许不得转载 | 当前页面:小贝博客 » typecho设置伪静态

评论