apache2.2环境codeigniter配置url地址重写

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>
以上两个的区别就是:一个是根目录,一个是二级目录。
6、重启apache,搞定。

About 智足者富

http://chenpeng.info

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>