##隐藏index.php
在项目根目录下新建一个.htaccess文件,然后重写路由,代码如下: RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ /sybwj/index.php/$1 [L]
【因为我项目的地址是http://xxxx.com/sybwj,所以是/sybwj/index.php,如果你的网站地址是http://xxxxx.com/,那么 那部分就应该写成/index.php。(注:在apache写进行路由重写要开启路由重写模块。在httpd.conf中开启)。】
在config.php中配置 原本:$config['index_page'] = 'index.php';
改为:$config['index_page'] = '';
【到这里ci在apacha下URL的index.php自动隐藏配置已经完成】
##静态资源配置 ###因为当你想加载js或css资源的时候,会发现老是会加载失败。原因是ci把你的请求直接进入index.php进行访问了。所以还是得在.htaccess中做配置。很简单,刚才里面的代码:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ /sybwj/index.php/$1 [L]
#####在RewriteCond $1 !^(index.php|images|assets|robots.txt)里面加上你的静态资源目录名称(必须在根目录下),比如说是static,则改为RewriteCond $1 !^(index.php|images|assets|static|robots.txt),在这里面加上static就ok了。