Nginx服务器 在域名隐藏/去掉index.php(网站伪静态)

3289 2019-04-22 Nginx

一、前言


为什么要去除index.php呢,因为去除index.php可以使得url看上去优雅不少,同时对SEO静态化有一定的好处。本文就主要针对于Nginx的web服务进行配置讲解。

二、Nginx 配置隐藏index.php


本文以一个 后端 ThinkPHP项目 为例,演示一下配置,重写主要使用到rewrite模块。综合配置如下:

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