CI URI有效删除index.php(完善CI手册)

       秉承MVC架构的思想,CI中的全部控制器都须要通过单点入口文件index.php(默认)来加载调用。也就是说,在默认状况下,全部CI开发项目的URL都形如如下这种形式:php

http://localhost/index.php/welcome很显然,默认状况下,index.php在URL地址段中的存在必定程度上影响了URL的简洁和SEO的进行。咱们能够经过下面本文介绍的方法来去掉这个讨厌的Index.php。nginx

你或许已经注意到在CodeIgniter用户手册中,已经存在关于此问题的解决方法。但官方提供的这个.htaccess配置,并非全部时候都能解决问题。下面通过笔者调试操做步骤供你们分享:
前提:服务器配置使用Apache做为Web服务器。
apache

一、将如下配置信息复制并保存为.htaccess文件(.htaccess文件放置在根目录下,即与application目录同级),服务器

默认状况下,index.php 文件将被包含在你的 URL 中:架构

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

你能够很容易的经过 .htaccess 文件来设置一些简单的规则删除它。ide

-----------------------------------------------------------------网站

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L
-----------------------------------------------------------------
this

 

注意:若是你的项目不在根目录请把上面这一句改成:RewriteRule ^(.*)$ index.php/$1 [L] 在上面的例子中,能够实现任何非index.php、images 和 robots.txt 的 HTTP 请求都被指向 index.php。spa

(第一步操做与CI操做手册中相同)

二、修改完成后咱们访问CI默认欢迎页面(http://localhost/welcome)时,会报错,错误信息以下:

--------------------------------------------------------------

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@sky00.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log. 

 --------------------------------------------------------------------------------------

我看了下这里网站里的全部东西都是这样报错,就是图片和TXT也打不开,而后查看了一下程序发现里面有三个文件.htaccess、httpd.ini、nginx.conf,我想应该是这几个家伙在做怪,首先想到的就是.htaccess这个分布文件,将其删除,果断打开网站了,那么找到缘由了,把删除了的找回来,去apache里开启.htaccess就行了,下面是开启方法:

在apache配置文件httpd.conf中找到

Options FollowSymLinks
AllowOverride None

有的版本是这样写的

Options FollowSymLinks ExecCGI Indexes
AllowOverride None

总之无论怎么写,你只须要把下面的

AllowOverride None改成AllowOverride All

而后在找到

LoadModule rewrite_module modules/mod_rewrite.so

把这个前面的“#”号去掉,就是去掉注释,而后重启apache.搞定!

相关文章
相关标签/搜索