PHP ci 域名去掉index.php

我在本地配置虚拟主机,访问api目录是:api.com/index.php/test/test。这个目录也可以这么访问:127.0.0.1/api/index.php/test/test

可以配置如下:

1,增加.htaccess到根目录,.htaccess内容如下:

RewriteEngine on

RewriteCond $1 !^(index.php|images|robots.txt)

RewriteRule ^(.*)$ /index.php/$1 [L]

2,修改application/config/config.php文件:

$config['index_page'] = 'index.php';修改为:

$config['index_page'] = '';

然后本地可以直接通过api.com/test/test访问,但是如果用127.0.0.1/api/index.php/test/test 访问的话,中间的index.php必须加上,

有方法可以不用加吗?(最好是不要修改环境,而通过配置代码)

原文地址:https://www.cnblogs.com/ayanboke/p/10118223.html