yii随笔(三) 开启友好路径

原文地址:http://ivhong.com/?p=101(ivhong.com 是我的博客主址)


概述:实现 localhost/site/login  访问 localhost/index.php?r=site/login


1. web server 配置

    a. nginx 配置

   location / {

           try_files $uri $uri/ /index.php?$args;

   }


   b. apache 配置

   DocumentRoot "webroot"

   <Directory "webroot">
       RewriteEngine on

       # If a directory or a file exists, use the request directly
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       # Otherwise forward the request to index.php
       RewriteRule . index.php

       # ...other settings...
   </Directory>


2. 在配置文件中的 components 里 添加如下(配置urlManager)

     'urlManager' =>[
            'class' => 'yii\web\UrlManager',
            'showScriptName' => false,
            'enablePrettyUrl' => true,
        ],

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章