zoukankan      html  css  js  c++  java
  • yii框架 隐藏index.php 以及美化URL(pathinfo模式访问)

    首先我们分步骤来:

    安装好 yii 以后  我们看到的url地址如下所示:

    http://www.3w.com/MyApp/backend/web/index.php?r=site%2Flogin

    我们首先去掉 index.php

    1.去apache配置中开启rewirte模块 

    2.配置好我们的虚拟主机  必须开启外部重写规则:

    3.在下面的目录下 创建   .htaccess  文件

    4.     .htaccess文件里内容如下:

     
    [php] view plain copy
     
     
    print?
    1. <code class="language-php"><span style="font-size:18px;"><strong>Options +FollowSymLinks    
    2. IndexIgnore */*    
    3. RewriteEngine on    
    4.   
    5. if a directory or a file exists, use it directly    
    6. RewriteCond %{REQUEST_FILENAME} !-f    
    7. RewriteCond %{REQUEST_FILENAME} !-d    
    8.   
    9. # otherwise forward it to index.php    
    10. RewriteRule . index.php  </strong></span></code>  
    1.  
      Options +FollowSymLinks
    2.  
      IndexIgnore */*
    3.  
      RewriteEngine on
    4.  
       
    5.  
      # if a directory or a file exists, use it directly
    6.  
      RewriteCond %{REQUEST_FILENAME} !-f
    7.  
      RewriteCond %{REQUEST_FILENAME} !-d
    8.  
       
    9.  
      # otherwise forward it to index.php
    10.  
      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.添加如下代码:

    1.  
      'urlManager' => [
    2.  
      'enablePrettyUrl' => true,//开启url美化
    3.  
      'showScriptName' => false,//隐藏index.php
    4.  
      'suffix' => '.html',//后缀
    5.  
      ],


    3.然后就成功了,试试吧

  • 相关阅读:
    组合
    面向对象初识, 类名,对象的的使用, 类名称空间和对象名称空间
    内置函数2 递归函数
    内置函数~~~
    生成器 列表推导式 列表表达式
    函数名应用 闭包 迭代器
    函数 动态参数, 名称空间 作用域 取值顺序,函数的嵌套
    函数初识~~
    文件操作要点
    Mysql索引原理
  • 原文地址:https://www.cnblogs.com/liangzia/p/9705455.html
Copyright © 2011-2022 走看看