yii的pathinfo方式实现

yii2.0在浏览器中默认查看控制器下的方法是  http://ltbk.cn/index.php?r=login/login

要是在浏览器上输出 http://ltbk.cn/index.php/login/login就更加方便

下面解决方法:

1.  打开config目录下的web.php,在$config = [ ‘components’=>[] ]中加入以下内容:

'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'http://m.'.$params['domain'].'/<c:[a-z0-9]+>/<a:[a-z0-9]+>' => 'mobile/<c>/<a>',
'http://m.'.$params['domain'].'/' => 'mobile/default/index',
],
],
不过路径还是形如:ltbk.cn/index.php/post/index

2.配置Apache
在yii2.0 默认的入口文件 web/index.php 的同一级下创建一个文本文件 命名为.htaccess
并添加内容

Options +FollowSymLinks
IndexIgnore */*
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

3.重启Apache




原文地址:https://www.cnblogs.com/l-zl/p/6640702.html