在ThinkPHP5.0中,出于优化的URL访问原则,还支持通过URL重写隐藏入口文件,下面以Apache为例说明隐藏应用入口文件index.php的设置。
下面是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]
本地测试中出现问题,提示:No input file specified.
解决办法是,把最后一句:RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
改为:RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
在index.php后面加一个问号即可。
nginx下可以在conf文件中location / 之后加入以下代码:if (!-e $request_filename)
{
#地址作为将参数rewrite到index.php上。
rewrite ^/(.*)$ /index.php/$1;
#若是子目录则使用下面这句,将subdir改成目录名称即可。
#rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
}
修改之后代码为:location / {
index index.html index.htm index.php;
#autoindex on;
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php/$1;
#rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
}
}