默认情况下,index.php 将被包含在你的 URL 中:
internetwork.net/index.php/news/article/my_article
你可以很容易的通过 .htaccess 文件来设置一些简单的规则删除它。下面是一个例子,使用“negative”方法将非指定内容进行重定向:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
注意:如果你的项目不在根目录请把上面这一句改为:RewriteRule ^(.*)$ index.php/$1 [L]
在上面的例子中,可以实现任何非 index.php、images 和 robots.txt 的 HTTP 请求都被指向 index.php。
官方方法的问题:
1. 没有说明.htaccess文件创建到哪个目录;.htaccess文件放到index.php所在目录,一般为CodeIgniter跟目录。
2. 不用管application和system目录中的.htaccess
3. 若项目不在根目录,则需要在最后一句语句加上ci所在目录的路径, RewriteRule ^(.*)$ /ci_dir/index.php/$1 [L]
eg. index.php文件在wwwroot\codeigniter,wwwroot是跟目录,则最后一句改为 RewriteRule ^(.*)$ /codeigniter/index.php/$1 [L]
4. [中级] 有效删除URL中的index.php http://shop.internetwork.net/forums/thread-15444-1-1.html 这个博客中的RewriteCond $1 !^(index\\.php|images|robots\\.txtl)最后多了一个l
5. apache一般默认都加载了重写模块,具体可以查看 Apache\conf\httpd.conf文件
LoadModule rewrite_module modules/mod_rewrite.so
以下内容不需要修改
<Directory />
Options FollowSymLinks
AllowOverride none
Order deny,allow
Deny from all
</Directory>
6. 不需要修改application/config/config.php中的$config['index_page'] = 'index.php';
标签:CodeIgniter
顶一下
(0)
0%
踩一下
(0)
0%