yii的pathinfo方式实现

本文介绍如何在Yii2框架中实现URL美化,并提供详细的步骤,包括修改配置文件、设置Apache服务器规则及重启Apache等。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值