URL 重写

可以通过 URL 重写隐藏应用的入口文件 index.php,下面是相关服务器的配置参考:

[ Nginx ]

  1. 在 nginx 虚拟主机 location 配置中添加规则,规则如下:
location / {
    if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=/$1  last;
        break;
    }
}

[ Apache ]

  1. httpd.conf 配置文件中加载了 mod_rewrite.so 模块
  2. AllowOverride None 将 None 改为 All
  3. 把下面的内容保存为.htaccess 文件放到应用入口文件的同级目录下
Options +FollowSymlinks -Multiviews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

[ IIS ]

如果你的服务器环境支持 ISAPI_Rewrite 的话,可以配置 httpd.ini 文件,添加下面的内容:

RewriteRule (.*)$ /index\.php\?s=$1 [I]

在 IIS 的高版本下面可以配置 web.Config,在中间添加 rewrite 节点:

更新时间:2026-03-23 22:29:01

文章目录