Yii Framework Forum: 隐藏index.php的步骤 - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

隐藏index.php的步骤 Rate Topic: -----

Poll: 隐藏index.php的步骤 (33 member(s) have cast votes)

隐藏index.php的步骤

  1. (33 votes [100.00%])

    Percentage of vote: 100.00%

  2. (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#1 User is offline   dreaminto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 59
  • Joined: 25-February 09

Posted 12 March 2009 - 01:29 AM

经自己的实践,总结一下隐藏index.php文件的步骤
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,//注意false不要用引号括上
            'urlSuffix'=>'.html',
                  'rules'=>array(
                      'sites'=>'site/index',
                  ),
            ),
            ...
        ),
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

这样就可以实现隐藏index.php入口文件了。

第一次发贴,有不对的地方,请大家指正。
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 12 March 2009 - 08:35 AM

多谢分享你的经验!
0

#3 User is offline   银河王子 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 16-May 09

Posted 17 March 2010 - 09:43 PM

终于找到了 执行成功 :rolleyes:
0

#4 User is offline   Dennis.Lan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 12-September 10

Posted 14 September 2010 - 12:30 AM

good job
0

#5 User is offline   xiexinze 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 28-October 10

Posted 29 November 2010 - 09:33 PM

:rolleyes: 谢谢分享
0

#6 User is offline   evoself 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 04-October 10

Posted 22 December 2010 - 10:04 PM

第二种方法好像不行啊
0

#7 User is offline   巡洋艦 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 316
  • Joined: 18-December 09
  • Location:Beijing, China

Posted 25 December 2010 - 11:05 AM

这里只有一种方法啊!你按步骤去做,应该是可以的!
0

#8 User is offline   Leric 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 12-December 08
  • Location:Bejing, China

Posted 18 January 2011 - 04:38 AM

分享一下我这儿的nginx下的配置吧:


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   500 502 503 504  /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;
    }
}


服务器环境是nginx + php5.3 fpm

域名信息就不改啦,也欢迎大家来看看 :)
Unfortunately no one can be told what Leric is - you have to see him for yourself.
0

#9 User is offline   winds 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 25-March 11
  • Location:http://www.dlf5.com

Posted 27 March 2011 - 08:32 PM

我是来吸收经验的!你们不用理我!
0

#10 User is offline   nettrinity 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 208
  • Joined: 15-March 11

Posted 15 April 2011 - 04:46 PM

View PostLeric, on 18 January 2011 - 04:38 AM, said:

分享一下我这儿的nginx下的配置吧:


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   500 502 503 504  /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;
    }
}


服务器环境是nginx + php5.3 fpm

域名信息就不改啦,也欢迎大家来看看 :)

请问你发的这个是什么啊? 干什么用的?为什么这么复杂?
0

#11 User is offline   巡洋艦 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 316
  • Joined: 18-December 09
  • Location:Beijing, China

Posted 15 April 2011 - 08:13 PM

这位兄弟分享的是nginx的配置
0

#12 User is offline   布老虎 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 08-December 09

Posted 07 May 2011 - 03:23 AM

IIS怎么隐藏index.php啊?
0

#13 User is offline   hiscaler 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 230
  • Joined: 17-October 09

Posted 09 June 2011 - 06:22 AM

看来 iis 不受待见啊。呵呵。我来分享一下:
[ISAPI_Rewrite]
RewriteRule /(?!static)(?!assets)(?!themes)(?!uploads)(.*)$ /index\.php [I,L]
复制之后保存成 httpd.ini放到根目录下就可以了。当然你的 iis 得安装 rewrite 组件。
0

#14 User is offline   巡洋艦 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 316
  • Joined: 18-December 09
  • Location:Beijing, China

Posted 11 June 2011 - 07:06 PM

View Posthiscaler, on 09 June 2011 - 06:22 AM, said:

看来 iis 不受待见啊。呵呵。我来分享一下:
[ISAPI_Rewrite]
RewriteRule /(?!static)(?!assets)(?!themes)(?!uploads)(.*)$ /index\.php [I,L]
复制之后保存成 httpd.ini放到根目录下就可以了。当然你的 iis 得安装 rewrite 组件。

很好,很强大!
0

#15 User is offline   scrooph 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 05-July 11

Posted 15 July 2011 - 03:57 AM

thank you!
man
0

#16 User is offline   Lugal 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 13-September 11

Posted 13 September 2011 - 10:57 PM

View PostLeric, on 18 January 2011 - 04:38 AM, said:

分享一下我这儿的nginx下的配置吧:


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   500 502 503 504  /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;
    }
}


服务器环境是nginx + php5.3 fpm

域名信息就不改啦,也欢迎大家来看看 :)


根据官方文档的话,nginx还需要分版本设置,以7.0为分割,nginx的locate中的写法都不一样。

这个是官方说明: http://www.yiiframew...x-php-on-nginx/
0

#17 User is offline   袁晨思 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 11-January 11

Posted 12 December 2011 - 12:05 AM

IIS 插件 ISAPI Rewrite最新版支持APACHE的
IndexIgnore */* 隐藏index.php
可以用这种方法
0

#18 User is offline   Lottery 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-February 12

Posted 07 February 2012 - 01:59 AM

现在看不懂,迟早会看懂的,顶顶
0

#19 User is offline   yiqing95 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 608
  • Joined: 27-December 10
  • Location:china

Posted 05 April 2012 - 09:06 AM

:lol:

留个脚印 !不错 谢谢大家的分享
0

#20 User is offline   starsw001 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 02-March 11

Posted 09 April 2012 - 09:55 PM

这个很不错。。。Nginx的配置。学习了。。。
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users