yii2下的路由重写

1.在config/main.php中添加配置信息

文件位置如图所示(图中展示的是backend下的config,也可以在fronted和common的config中添加)

配置的代码标准格式如下


'showScriptName' = false, // 禁用 index.php
'enablePrettyUrl' =true, // 启用 URL美化
'suffix' ='.html', // 在这里我们不配置,如果启用后缀,那么你的每个请求都会默认有.html的后缀


2.在web下添加.htaccess文件

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php






原文地址:https://www.cnblogs.com/fpcing/p/7412290.html