JOE个人网站

JOE个人网站,不仅仅是一个网站,更像是一个展现自我的平台,致力于让朋友们都可以
有所感触,有所收获。

Apache2.2.21下为codeigniter配置url地址重写 url可以不写index.php

2017-12-19 11:29:10
1、首先打开apache的配置文件,httpd.conf,找到#LoadModule rewrite_module modules/mod_rewrite.so,去掉前面的#号,开启mod_rewrite模块

2、找到
  <Directory />
    Options FollowSymLinks
    AllowOverride none
    Order deny,allow
    Deny from all
  </Directory>
  修改为:
  <Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
  </Directory>

3、找到
  <Directory "D:/Program Files (x86)/Web/www">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride none

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
  </Directory>
  修改为:
  <Directory "D:/Program Files (x86)/Web/www">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
  </Directory>
  以上主要是修改 AllowOverride one为 AllowOverride All

4、打开你的ci目录的application/config下的config.php,查找$config['index_page']变量,将它的值留空

5、为ci编写.htaccess文件,站长的CI安装在网站根目录的friend目录下,应此.htaccess的内容如下:
  <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /friend/index.php/$1 [QSA,PT,L]
  </IfModule>
  如果你的ci就是安装在网站根目录,那么,你的.htaccess内容应该为:
  <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php/$1 [QSA,PT,L]
  </IfModule>
 嗯,相信大家都看出区别了,就是多了一个ci的安装目录,但是却很重要。

6、重启apache,搞定。