yii框架 隐藏index.php 以及美化URL(pathinfo模式访问)
2024-09-23 17:52:22
首先我们分步骤来:
安装好 yii 以后 我们看到的url地址如下所示:
http://www.3w.com/MyApp/backend/web/index.php?r=site%2Flogin
我们首先去掉 index.php
1.去apache配置中开启rewirte模块
2.配置好我们的虚拟主机 必须开启外部重写规则:
3.在下面的目录下 创建 .htaccess 文件
4. .htaccess文件里内容如下:
- <code class="language-php"><span style="font-size:18px;"><strong>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 </strong></span></code>
- 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
5.现在再次在浏览器 访问我们的项目 我们就可以去掉index.php url 如下:
http://www.3w.com/MyApp/backend/web/?r=site%2Flogin
然后我们 美化 url 如下:
http://www.yii2.com/site/index.html
我们只需要在config目录下配置即可:
2.添加如下代码:
- 'urlManager' => [
- 'enablePrettyUrl' => true,//开启url美化
- 'showScriptName' => false,//隐藏index.php
- 'suffix' => '.html',//后缀
- ],
3.然后就成功了,试试吧
最新文章
- JS 数字,金额 用逗号 隔开(数字格式化)
- Java编译器如何生成重载和覆盖方法代码
- 【NOIP训练】【数论】超级计算机
- Android线程池(二)
- B - Plane of Tanks: Pro
- stack例子
- 江中微型统计分析软件V1.0版本完成
- expect set timeout -1 永不超时
- 使用Common.Logging与log4net的组件版本兼容问题
- ASP.NET MVC4通过UrlRewriter配置伪静态,支持html后缀
- 学习day02
- CSS3 移动端 1PX 线变成0.5PX
- 【BZOJ4032】[HEOI2015]最短不公共子串(后缀自动机,序列自动机)
- 嵌入式linux——说明(零)
- 055、创建macvlan网络 (2019-03-22 周五)
- Linux 驱动开发
- SpringBoot的学习【2.分析HelloWorld的依赖】
- linux、centos下安装配置vim
- 怎样从外网访问内网Node.js?
- 【摘】50个jQuery代码段帮助你成为一个更好的JavaScript开发者