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. POJ 2096-Collecting Bugs(概率dp入门)

    题意: 有n种bug和s种系统bug,每天发现一种bug(可能已经发现过了)所有种bug被发现的概率相同,求所有bug被发现的期望天数. 分析: dp[i][j]发现i种bug,j种系统bug期望天数 ...

  2. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 get_selected_list_label(self, locator)

    def get_selected_list_label(self, locator): """Returns the visible label of the selec ...

  3. new trip

    离开YY已经快一周了,特别感谢以前的老大姚冬和朱云峰,从他俩身上学到了很多.这个决定也经过了很长的纠结,不想再做个犹豫不决的人,所以最后还是坚定了最初的信念,也算是对半年前自己的一个完好交代,以防将来 ...

  4. json字符串转换为JSONObject和JSONArray

    一.下载json 具体到http://www.json.org/上找java-json下载,并把其放到项目源代码中,这样就可以引用其类对象了 二.具体转化过程 //JSONObject String ...

  5. 在fedora20下面手动为自己的安装程序创建桌面图标

    (博客园-番茄酱原创) 在/usr/share/applications/下面创建destktop文件,用于产生桌面图标 创建文件:touch android-eclipse.desktop 编辑文件 ...

  6. JAVA虚拟机之类加载器

    转载请声明:原文转自http://www.cnblogs.com/xiezie/p/5909570.html 1.JVM的生命周期 1.1 JVM的生命周期和程序的生命周期一致 1.2 JVM结束生命 ...

  7. phonegap WebApp

    打开网页浏览器,进入Android SDK网站(http://developer.android.com/sdk/index.html). 我们可以看到,Google官方提供了包括Windows平台在 ...

  8. Web Service 与 EJB 的分布式的区别

    EJB的分布式:一个业务逻辑可能会调用分布在多台服务器上的 EJB 组件,但是这么多的组件调用必须纳入一个事务范围之中.也就是说如果需要调用三个 EJB 组件,第一个调用成功,第二个调用成功,但第三个 ...

  9. Hibernate关联关系之——单向n-1

    1 .单向 n-1 关联只需从n的一端可以访问1的一端 2.域模型: 从Order到Customer的多对一单向关联需要在Order类中定义一个Customer属性,而在Customer类中无需定义存 ...

  10. 【转】使用JavaScriptCore在JS和OC间通信

    http://www.cocoachina.com/ios/20160623/16796.html iOS 开发中,我们时不时的需要加载一些 Web 页面,一些需求使用 Web 页面来实现可以更可控, ...