如何在Yii2中启用干净的urls。我想删除index.php和'?‘从url参数。为此,需要在Yii2中编辑哪个部分?
发布于 2014-10-25 02:25:20
我让它在yii2中工作。为Apache启用mod_rewrite。对于basic template,请执行以下操作:在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>',
),
],对于advanced template,在backend/web和frontend/web文件夹中创建.htaccess文件,并在common/config/main.php中添加urlManager组件
发布于 2015-04-07 07:02:23
第一个要点是,
在您的服务器(LAMP、WAMP、XAMP..etc)上启用了Module_Rewrite,以便在yii2框架中进行网址重新布线创建一个.htaccess文件并将其放入/web文件夹
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文件夹common/config/main-local.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>',
),
],发布于 2016-08-07 00:31:12
在nginx上这样配置
location / {
try_files $uri $uri/ /index.php$is_args$args;
}https://stackoverflow.com/questions/26525320
复制相似问题