|
首先,你要清楚自己的 Web 服务器是 Apache,支持 mod_rewrite,并且已经配置好 rewrite 相关的参数。
什么是 rewrtie 可以 Google 一下。 然后,在 CI 根目录下新建立一个配置文件,命名为: .htaccess 在里面这样写:
上面的代码意思是排除某些目录或文件,使得这些目录不会 rewrite 到 index.php 上,这一般用在图片、js、css 等外部资源上。也就是说非 PHP 代码都要排除出去。(这里我排除了 images 目录和 robots.txt 文件,当然 index.php 也应该被排除) 哦,对了,还要修改 config.php 这个文件中的下列内容: PHP复制代码 /* |-------------------------------------------------------------------------- | Index File |-------------------------------------------------------------------------- | | Typically this will be your index.php file, unless you've renamed it to | something else. If you are using mod_rewrite to remove the page set this | variable so that it is blank. | */ $config['index_page'] = "index.php"; 把其中的 "index.php" 改成 "" 就可以了。 | |
Hex 发表于 2008年2月15日 13:59 大神 我想问一下 为什么我的 RewriteEngine on RewriteCond 1ドル !^(index.php|images|robots.txt) RewriteRule ^(.*)$ /index.php/1ドル [L] 这么写就不行会显示 没有文件 把第三行 改成 RewriteRule ^(.*)$ /index.php?/1ドル [L] 就可以了 想请教一下 是什么原因 | |
|
我在nginx 下既隐藏了 url地址中的index.php 同时又能引入 静态资源 css.js等文件。具体配置是
rewrite .*/(statics|uploads)/(.*)$ /1ドル/2ドル last; | |
|
这个是,我用的,根目录下的,.htaccess文件:
| |
|
我用的
| |
|
补充一些我遇到的问题:
<Directory "D:/usr/local/www"> AllowOverride all Options +FollowSymLinks +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> Options参数设置如上,好像不开,无法使用rewrite功能 心得:APACHE的LOGS一定要多看 | |
|
RewriteEngine on
RewriteCond 1ドル !^(index.php|images|robots.txt) RewriteRule ^(.*)$ /index.php/1ドル [L] .htaccess这个文件中的代码就是以上三行么? | |
|
是的,但也需要根据你的目录情况进行修改!
具体你应该看看 apache rewrite 的相关手册!这是 apache 的问题,和 CI 没什么关系,呵呵〜 | |
|
谢谢楼上的回答,我使用的不是APACHE而是IIS,也是如上设置么?
| |
|
IIS 就不是这样了〜〜
有另外的 url rewrite 方法〜〜 不过,劝你还是用 apache。 PS: 不一定非要去掉 index.php 吧?带着没有什么不好,顶多就是不好看而已。 | |