ThinkPHP 隐藏 Index.php 的一些设置

ThinkPHP可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。

正常访问:

http://serverName/index.php/module/controller/action/param/value/...

如果是Apache环境的话,需要在入口文件的同级添加.htaccess文件,内容如下:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On
 
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>

如果是Nginx环境的话,可以在Nginx.conf中添加:

location / {
    // …..省略部分代码
    if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=/$1  last;
        break;
    }
}

 

分类目录

建站碰到问题了吗?

联系我们