CI框架如何删除URL中index.php的终极解决方案
2013-02-06 13:26
507 查看
文章来源:
你可以很容易的通过 .htaccess 文件来设置一些简单的规则删除它。下面是一个例子,使用“negative”方法将非指定内容进行重定向:
注意:如果你的项目不在根目录请把上面这一句改为:RewriteRule ^(.*)$ index.php/$1 [L]
在上面的例子中,可以实现任何非 index.php、images 和 robots.txt 的 HTTP 请求都被指向 index.php。
index位于根目录时,你可以在index.php所在的根目录里新建.htaccess文件并使用以下代码:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
当index.php不在根目录时,你可以在index.php所在目录里新建.htaccess文件并使用以下代码:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txtl)
RewriteRule ^(.*)$ /path_to_app/index.php?/$1 [L]
注意把path_to_app换成你的index.php所在文件的目录.假设你的index.php放在根目录的tool子文件夹下,你可以这样写:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txtl)
RewriteRule ^(.*)$ /tool/index.php?/$1 [L]
以上方案应该可以解决Apache环境下如何有效删除URL中index.php的问题,如果有其他问题,请评论或留言并留下一个有效的联系方式.我会尝试替您解决并将可能的解决方案及时通知您!
另外,关于IIS环境下如何有效删除URL中的index.php,可以参考这篇文章:
IIS7.5 去除 index.php web.config配置文件
CI框架如何删除URL中index.php的终极解决方案
利用动态网页技术生成的技术大都含有index.php,在不引起路由混乱的前提下,有效删除URL中的inde.php可以让网页地址看起来更友好!以下篇幅虽针对CI框架而言,但从其实现原理来看,对其他情况下类似问题的解决仍然是有较大参考价值的.官方解决方案
默认情况下,index.php 文件将被包含在你的 URL 中:example.com/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。
我的终极解决方案
但在实践中,以上方案仅适用于与运行于Apache环境下的服务器且并不具有充分的普遍适用性!当CI程序位于非根目录或位于某些虚拟主机上时,以上解决方案会引起”404错误”或”no input file specified”等错误.百度参考过相关问题的解放方案后,找到了一种具有通用性的有效删除URL路径中index.php的方法,代码参考如下:index位于根目录时,你可以在index.php所在的根目录里新建.htaccess文件并使用以下代码:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
当index.php不在根目录时,你可以在index.php所在目录里新建.htaccess文件并使用以下代码:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txtl)
RewriteRule ^(.*)$ /path_to_app/index.php?/$1 [L]
注意把path_to_app换成你的index.php所在文件的目录.假设你的index.php放在根目录的tool子文件夹下,你可以这样写:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txtl)
RewriteRule ^(.*)$ /tool/index.php?/$1 [L]
以上方案应该可以解决Apache环境下如何有效删除URL中index.php的问题,如果有其他问题,请评论或留言并留下一个有效的联系方式.我会尝试替您解决并将可能的解决方案及时通知您!
另外,关于IIS环境下如何有效删除URL中的index.php,可以参考这篇文章:
IIS7.5 去除 index.php web.config配置文件
相关文章推荐
- CI框架如何删除URL中index.php的终极解决方案
- ci框架中删除url中的index.php(rul重写)
- CI框架 .htaccess 隐藏url在index.php解决方案
- 有效删除CI框架中URL中的index.php
- 教你如何在CI框架中使用 .htaccess 隐藏url中index.php
- 教你如何在CI框架中使用 .htaccess 隐藏url中index.php
- CI框架如何删除地址栏的 index.php
- CI框架 .htaccess 隐藏url在index.php解决方案
- CI 框架(Apache环境)有效删除URL中的index.php 分类: CI框架 php 2014-01-20 13:17 266人阅读 评论(0) 收藏
- CI 框架(Apache环境)有效删除URL中的index.php
- 去除CI框架url链接中的index.php
- CI 框架去除URL上的index.php 来直接访问
- centos nginx环境下删除CI框架Index.php入口遇到404问题
- laravel框架如何去掉URL中index.php
- 如何去除ci框架中显示的index.php
- 在nginx下去掉ci框架url中的index.php
- CI 框架去掉url 中index.php的方法
- 如何去掉CI (codeigniter)url中的index.php
- CI框架 .htaccess 隐藏url中index.php的解决
- CI框架在Apache服务器下去掉URL中的index.php