不管是为了伪静态还是为了url美观,我们经常需要隐藏掉项目的入口文件index.php。
在thinkphp(3.2.x)中你首先需要去项目的配置文件config.php中把路由模式先改为pathinfo模式('URL_MODEL' => '2',),然后需要配置下apache或者nginx。
nginx写法
location / {
if (!-e $request_filename){
rewrite ^/index.html/?$ /index.php?s= last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
然后重启nginx xx/sbin/nginx -s reload
Apache写法
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(Uploads)
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
同样重启apache服务