zoukankan      html  css  js  c++  java
  • Yii地址美化(nginx环境)

    通过urlmanager实现yii地址美化,需配合服务器中的rewrite配置

       

    1、在'components'中加入
       'urlManager'=>array(
           'urlFormat'=>'path',                 //使用pathinfo模式,不需要?r=
           'showScriptName'=>false,             //隐藏index.php
           'rules'=>array(                      //这里面写规则,下文再做解释
               'pattern1'=>'route1',
               'pattern2'=>'route2',
               'pattern3'=>'route3',
           ),
       ),

    2、在nginx中配置
    找到相应站点的配置文件,nginx.conf,但如果你是lnmp,它会自动调用conf里的站点配置文件,你可在/usr/local/nginx/conf/vhost 中找到。
    添加以下规则:(fastcgi_pass视具体服务器配置而定,不必更改。若规则已存在,加入红色两行)
        location ~ .*.(php|php5)?$ {
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fcgi.conf;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;

        }

    若你在1中配置urlmanager为不显示index.php,则还需要添加如下规则:
        location / {
            if (!-e $request_filename){
                rewrite ^/(.*) /index.php last;
            }
        }

        # if(!-e $request_filename)的意义是先确定访问地址是否是真实存在的文件,否不是,则 rewrite 至 index.php


    3、在apache中配置

    在根目录下建立 .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

  • 相关阅读:
    问题-第三方控件卸载与安装错误指南(运行期错误)
    版本号规则
    WCF入门学习3-配置文件与部署iis
    在Unity3D中连接WCF服务端
    WCF入门学习2-控制台做为宿主
    WCF入门学习1-最简单的一次通信
    闭包一个容易忽视的小问题及解决方法
    Vector3.Set的正确使用
    string.format的用途联想
    Unity的旋转-四元数,欧拉角用法简介
  • 原文地址:https://www.cnblogs.com/songqiaoli/p/3262366.html
Copyright © 2011-2022 走看看