yii 隐藏index.php的步骤

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-8;
    
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:9000;
        
#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
;
   
}
}

 

posted @ 2014-02-16 16:24  zhepama  阅读(1266)  评论(0编辑  收藏  举报