gpt4 book ai didi

yii2 - 在 Yii2 中启用干净 URL

转载 作者:行者123 更新时间:2023-12-02 17:44:21 25 4
gpt4 key购买 nike

如何在 Yii2 中启用干净的 url。我想删除index.php 和'?'来自 url 参数。为此需要在 Yii2 中编辑哪一部分?

最佳答案

我在 yii2 中工作了。为 Apache 启用 mod_rewrite。对于基本模板,请执行以下操作:在 web 文件夹中创建一个 .htaccess 文件并添加此

RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

然后在config文件夹中,在web.php中添加到组件

'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],

对于高级模板,在backend/webfrontend/web内创建.htaccess文件文件夹并在 common/config/main.php

中添加 urlManager 组件

关于yii2 - 在 Yii2 中启用干净 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26525320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com