myst729 发表于 2011-8-6 15:27:18

请教一个URI路由的问题

本帖最后由 myst729 于 2011-8-6 15:35 编辑

php 菜鸟,CI 新手

我所有 controller 中都只有一个 index 函数,接受一个数字参数的
初始的URL结构是 http://localhost/ci/index.php/mycontroller/index/123

首先是根据文档教的方法在 .htaccess 中写入

RewriteEngine on
RewriteCond $1 !^(index\.php|public|robots\.txt)
RewriteRule ^(.*)$ index.php/$1


把 index.php 去掉,成了 http://localhost/ci/mycontroller/index/123

然后在 routes.php 里加入
$route['(:any)/(:num)'] = "$1/index/$2";
现在可以通过 http://localhost/ci/mycontroller/123 访问到了

遇到的问题是,我把 css,img,js 这些静态资源放在 http://localhost/ci/public/ 目录的(硬盘上的 d:\wampserver\www\ci\public\)
现在只能通过 http://localhost/ci/public/css/style.css,http://localhost/ci/public/img/pic.png 访问到
如果我希望把 public 去掉,通过 http://localhost/ci/css/style.css,http://localhost/ci/img/pic.png 这样的路径去访问
是应该编辑 routes 还是 .htaccess 呢?

两种方法都试了,都没有搞定,请指教,谢谢。

myst729 发表于 2011-8-8 11:19:18

求助,自己顶一下……

jeongee 发表于 2011-8-8 11:47:42

本帖最后由 jeongee 于 2011-8-8 11:48 编辑

明显是.htaccess但是感觉有点无聊,你那是不喜欢public,你不如直接建css和image文件夹了,何必在外面包一层

Hex 发表于 2011-8-8 13:30:14

非 PHP 文件无法用路由实现,必须用 URL Rewrite。
页: [1]
查看完整版本: 请教一个URI路由的问题