thinkphp5配置入口路径

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Feihongxiansen/article/details/78865093

在使用thinkphp5框架开发的项目当中,默认的访问路径格式一般都带有public/index.php,即使是访问网站主页,也得加上public才可以,但这是很不友好的,就且论用户体验来说,人家申请了一个域名,访问网站的时候不可能让人写了域名在加上public/index.php吧。在此之前我在网上查阅过很多资料,都没能帮我彻底的问题,最后摸索出解决办法如下:

所用服务器工具:phpStudy(WAMPServer也一样)

首先打开配置文件httpd-vhosts-conf,然后修改网站根目录到public文件夹

<VirtualHost *:80>

    ServerName localhost

    DocumentRoot "d:/wampserver/wamp64/www/public"

    <Directory  "d:/wampserver/wamp64/www/public/">

        Options +Indexes +Includes +FollowSymLinks +MultiViews

        AllowOverride All

        Require local

    </Directory>

</VirtualHost>

然后修改thinkphp框架里面public文件夹下的的.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>

修改为如下:

<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>

其实就增加了一个字符,在倒数第二行的index.php后面加了个?,即可实现网站入口问件的修改。

猜你喜欢

转载自blog.csdn.net/Feihongxiansen/article/details/78865093