加了.htaccess文件为什么仍不能去掉index.php?
我已经写了.htaccess文件,方法是没错误的,rewrite url 我也打开了,但还是不能去掉index.php。 请说明具体情况。能不能去掉 index.php 要看规则写的对不对,和 .htaccess 文件无关。 我的在localhost下可以去掉index.php,同样的方法,在虚拟的127.0.0.2下就不能重定向了,奇怪。不知为何 本帖最后由 13880411700 于 2011-11-2 15:19 编辑
$config['index_page'] = 'index.php';
改为
$config['index_page'] = '';
apache下的httpd.conf需要改一下
<Directory "D:\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 #这里默认是None,改成All,重启
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory> 1. 在httpd.conf中,将 所有 AllowOverride None改为 AllowOverride All 好像共有三处吧,然后重启apache
2. 在.htaccess文件中,是这样的配置:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots|stafile|upload|\.txt)
RewriteRule ^(.*)$ /index.php/$1
如果你是直接在根目录配置的,则以上就可以了;假如你的项目在根目录底下一层,则 RewriteRule ^(.*)$ /index.php/$1 得变为RewriteRule ^(.*)$ /项目文件夹名/index.php/$1
以上两步已经可以去掉 index.php了,假如项目中的路径,为了去掉index.php,还需要第 3 步 操作,因为第 3 步 是影响到 site_url();这个函数的。
3. 将 config.php中的$config['index_page'] = 'index.php';改为 $config['index_page'] = ''; $config['index_page'] = 'index.php'; 值改为空。
页:
[1]