在使用thinkphp 5开发restful API时经常会遇到路由配置问题。那么如何在隐藏请求URL中的index.php,让请求地址更加美观呢?
解决方法如下,在项目根目录新建 .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]
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
</IfModule>