Yii2 Apache 隐藏index.php并美化url

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

1、配置Apache
1.1、开启重写配置

#在Apache配置文件中,开启
LoadModule rewrite_module modules/mod_rewrite.so
#同时确保modules文件夹下存在改文件

1.2、开启允许配置

AllowOverride None    配置为 AllowOverride All

这里写图片描述

2、Yii2配置

'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
    ],
],

3、添加.htaccess文件

#在与index.php同目录的文件夹中新增名为 .htaccess的文件,内容为:
<IfModule rewrite_module>
    Options +FollowSymLinks
    IndexIgnore */*
    RewriteEngine On


    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php
</IfModule>

4、重启Apache

本人亲测可以

猜你喜欢

转载自blog.csdn.net/eddy23513/article/details/82286305