解决 codeigniter 3 无法通过URI 访问地址()

时间:2022-07-16 18:27:16

故事发生在昨天我电脑中毒重装系统之后。我把codeigniter 重新引入到环境目录之后,就再也无法通过 exmple.com/class/function 的形式访问项目了。于是我试图找apache配置的错误。更改apache 设置。更改 index.php ,删除.htaccess 之后。结果是都!不!管!用!于是我又开始尝试是否是环境的问题,下了一个wordpress 然后我发现。什么啊?work correctly,It's make a sence 啊。在然后我确定了,这个绝对不是apache 本身配置的问题,于是上CI的官网一查,各种trouble shooting .各种配置方法。然后我发现。还是!TMD不管用啊。你这在玩我吗?于是我怀着绝望的心情艰辛的随便翻了一下URL的章节,我发现我qu,你是在逗我吗?

By default, the index.php file will be included in your URLs:

example.com/index.php/news/article/my_article

是在逗我吗?为什么毛不再文档开始就注明呢。
然后下面又说

If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the “negative” method in which everything is redirected except the specified items:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]

你就不能在开始欢迎页面就注明吗。没有这么坑爹的。

其实解决方法很简单,复制上面的规则(红色字)。在自己的CI项目根目录建立.htaccess(apache 访问规则帮助)文件。其意思就是说把你所有访问都重定向到index.php
这样就不用再在路径里面加入index.php了————————————————

于是done 一起又完美了。
不过归根究底我总结。
遇到问题一定要冷静,
首先用排除法。确定问题根源。
其次。一定要在tmd 阅读文档啊,阅读官方文档啊。好好阅读啊!