Apache

1.开启apache的mod_rewrite模块
      去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符号
      确保<Directory "..."></Directory>中有“AllowOverride All”
2.在项目中的/protected/config/main.php中添加代码:

      'components'=>array(
...
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'/',
'<controller:\w+>/<action:\w+>'=>'/',
'manage' => 'content/index',
'manage/<controller:\w+>' => '',
'manage/<controller:\w+>/<action:(update|delete|view)>/<id:\d+>' => '/',
'manage/<controller:\w+>/<action:(create|update|delete|admin|view|changepswd|empty)>' => '/',
'post/<id:\d+>/<title:.*?>'=>'post/view',//此处重要:把post/id/title映射为:post/view/id/title/6
'posts/<tag:.*?>'=>'post/index',//此处重要:把通过“posts/tag”访问的链接变成post/index/tag
),
),
...
),

3.在与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

NGINX

nginx versions .7 and higher:

server {
    set $yii_bootstrap "index.php";
    charset utf-;
    client_max_body_size 128M;     listen 80; ## listen for ipv4
    #listen [::]:80 default_server ipv6only=on; ## listen for ipv6     server_name mysite.local;
    root        /path/to/project/web;
    index       $yii_bootstrap;     access_log  /path/to/project/log/access.log  main;
    error_log   /path/to/project/log/error.log;     location / {
        # Redirect everything that isn't real file to yii bootstrap file including arguments.
        try_files $uri $uri/ /$yii_bootstrap?$args;
    }     # uncomment to avoid processing of calls to unexisting static files by yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;     location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_pass   127.0.0.1:;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
    }     location ~ /\.(ht|svn|git) {
        deny all;
    }
}

When using this configuration, you should set cgi.fix_pathinfo=0 in the php.ini file in order to avoid many unnecessary system stat() calls.

或者nginx versions prior to .7:

server {
    listen       80;
    server_name  .yeegt.com;     charset utf-8;     location /{
        root   /home/yeegt/yiigt;
        index  index.php;
        try_files $uri $uri/ /index.php?$args;
    }     location ~^/protected/{
        deny  all;
    }     # redirect server error pages to the static page /50x.html
    #
    error_page   500502503504  /50x.html;
    location =/50x.html {
        root   html;
    }     location ~*.(js|jpg|jpeg|gif|png|ico)$ {
        root /home/yeegt/yiigt;
        expires 356d;
    }     location ~\.php$ {
        root           /home/yeegt/yiigt;
        fastcgi_pass   127.0.0.1:9010;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/yeegt/yiigt$fastcgi_script_name;
        include        fastcgi_params;         set $path_info $request_uri;         if($request_uri ~"^(.*)(\?.*)$"){
            set $path_info $1;
        }
        fastcgi_param PATH_INFO $path_info;
    }
}

yii 隐藏index.php的步骤的更多相关文章

  1. yii 隐藏index.php

    首先,开启apache的rewrite模块 去掉rewrite前的#,如下所示 LoadModule rewrite_module modules/mod_rewrite.so 接着,在yii的ind ...

  2. Yii Framework隐藏index.php文件的步骤

    Yii Framework隐藏index.php文件的步骤 作者:feebas 发布于:2012-4-23 13:36 Monday 分类:Yii Framework 1.开启apache的mod_r ...

  3. yii框架 隐藏index.php 以及美化URL(pathinfo模式访问)

    首先我们分步骤来: 安装好 yii 以后  我们看到的url地址如下所示: http://www.3w.com/MyApp/backend/web/index.php?r=site%2Flogin 我 ...

  4. Yii 1.1 URL两个笔记 同时支持PATH于GET路由和隐藏index.php

    同时支持PATH于GET格式路由(修改框架文件 简直坑) framework/web/CUrlManager.php parseUrl方法 第一行判断修改成 if($this->getUrlFo ...

  5. CI 框架隐藏index.php-ubuntu

    和朋友在做一个小网站,用到了CI框架,之前测试都是在windows上,隐藏index.php也相对比较简单.但服务器是ubuntu系统,需要配置一下,根据网上看到的一些教程,结合自己电脑的特点,记录步 ...

  6. url优化|隐藏index.php

    隐藏index.php   一.codeigniter codeigniter和许多php框架一样,有个单一入口index.php,从url上看,显得很不友好.通过apache的rewirte,是可以 ...

  7. Yii2.0简单隐藏index.php文件和模块配置和layout布局配置禁用和日志写入配置

    隐藏index.php文件 目的:想去掉浏览器地址栏中的 index.php?r= 这一块. 在/config/web.php中   ’components'=>[]   中添加如下代码: 'u ...

  8. thinkphp中redirect重定向后隐藏index.php

    首先,.htaccess文件要配置好隐藏index.php.系统默认生成的就行. 然后,也是最关键的一部,要在Application/Home/Conf里的config.php文件中增加如下配置: & ...

  9. tp5 隐藏index.php 邓士鹏

    tp5 隐藏index.php ------------------------------------------------------------------------------------ ...

随机推荐

  1. HDU 1025-Constructing Roads In JGShining's Kingdom(最长不降子序列,线段树优化)

    分析: 最长不降子序列,n很大o(n^2)肯定超,想到了小明序列那个题用线段树维护前面的最大值即可 该题也可用二分搜索来做. 注意问题输出时的坑,路复数后加s #include <map> ...

  2. 【剑指offer 面试题14】调整数组顺序使奇数位于偶数前面

    思路: 头尾指针,向中间遍历,依据条件交换元素. #include <iostream> using namespace std; void reOrder(int *pData, uns ...

  3. JQuery笔记:JQuery和JavaScript的联系与区别

    来源:http://www.ido321.com/1019.html ps:LZ觉得这个标题有点大了,超出了能力范围,不喜勿碰.目前只记录LZ能力范围内的,日后持续补充. 一.JQuery对象和DOM ...

  4. bfs CCF2016第七次 游戏

    // bfs CCF2016第七次 游戏 // 思路: // O(300*100*100) // 直接暴搜 // 注意,同一格同一时间不能经过两次!!! #include <bits/stdc+ ...

  5. 我的web前端修炼之路从此开始

    看过一篇文章,上面说过要想学习一门新技术,从什么时候开始都是不晚的.但对于一名大四的学生,只会一点简单的网页架构,只懂得HTML,CSS,JavaScript简单的一点皮毛,却怎么也说不过去.但也是这 ...

  6. How do I use SOCKS proxy in delphi?

    TCP====== For Indy 8.0 In Delphi, do the following: IdTCPClient1.SocksInfo.Host := [the DNS name of ...

  7. [置顶] Kendo UI开发教程: Kendo UI 示例及总结

    前面基本介绍完Kendo UI开发的基本概念和开发步骤,Kendo UI的示例网站为http://demos.kendoui.com/ ,包含了三个部分 Web DemoMobile DemoData ...

  8. 现代程序设计homework-06

    现代程序设计homework-06 1) 把程序编译通过, 跑起来. 加入了倒退的功能,程序已经能跑起来了(见代码). 不过倒退功能有些bug,不过这是由于原本程序的主逻辑就有点问题(对于不可走的格子 ...

  9. Android问题-打开DelphiXE8与DelphiXE10编译空工程提示“[Exec Error] The command exited with code 1.”

    问题情况:开发了半天的D2007代码,想测试一个安桌程序,发现新建空工程,提示失败. 提示如下 Exec Error] The command PATH C:\Program Files (x86)\ ...

  10. Com进程通信(Delphi2007)

    相关资料: 1.http://my.oschina.net/u/582827/blog/2847662.http://www.cnblogs.com/findumars/p/5277561.html3 ...