关于lamp去掉index.php

来源:互联网 发布:淘宝友情链接有什么用 编辑:程序博客网 时间:2024/06/09 13:47
一》在linux里面设置 1.打开apache的配置文件,conf/httpd.conf :LoadModule rewrite_module modules/mod_rewrite.so,把该行前的# 去掉 。 搜索 AllowOverride 搜索None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为AllowOverride All。【其实apache 默认的都已经打开的】2.在 CI 的根目录下,即在 index.php ,system的同级目录下,建立.htaccess,直接建立该文件名不会成功,可以先建立记事本文件,另存为该名的文件即可。内容如下( CI 手册上也有介绍): RewriteEngine on   RewriteCond $1 !^(index\.php|images|robots\.txt)   RewriteRule ^(.*)$ / index.php /$1 [L] 如果文件不是在www的根目录下,例如是: http://localhost/nianyi_2011/ index.php ,第三行需要改写为RewriteRule ^(.*)$ /nianyi_2011/ index.php /$1 [L] 另外,如果你的网站的根目录下面还有其他的文件夹,例:js,css,images,config等等文件夹,这需要过滤除去,第二行需要改写为: RewriteCond $1 !^index\.php|images|js|css|config|robots\.txt)。 3.将 CI 中配置文件(application/config/config.php)中$config['index_page'] ="index.php ";改写成$config['index_page'] = ""; 4.ok,完成。还要记得重启apache。二》在 windows 里面开发以上的配置在 windows 上面是不起任何作用的,所以我们在 windows 里面需要设置我们的apache的虚拟主机,在apache里面找到Apache-20\conf\extra\httpd-vhosts.conf 这个文件【我用的是服务是PHPnow,很多的人用wamp】,同样找到此文件,在里面修改,例: # http://www.PHPnow.org # filename: httpd-vhosts.conf <Directory ../vhosts>     AllowOverride All     Order allow,deny     Allow from all </Directory> NameVirtualHost * <VirtualHost *>     DocumentRoot ../htdocs     ServerName default:80     ErrorLog logs/default-error_log </VirtualHost> 修改成: # http://www.PHPnow.org # filename: httpd-vhosts.conf <Directory ../vhosts>     RewriteEngine on       RewriteCond $1 !^(index\.php|images|js|css|config|robots\.txt)       RewriteRule ^(.*)$ / index.php /$1 [L]     AllowOverride All     Order allow,deny     Allow from all </Directory> NameVirtualHost * <VirtualHost *>     DocumentRoot ../htdocs     ServerName default:80     ErrorLog logs/default-error_log </VirtualHost> 也就是把路由写到这里面来。记得重新启动服务。继续修改你的配置文件: $config['enable_query_strings'] = true $config['controller_trigger'] = 'c'; $config['function_trigger']  = 'm'; 把$config['enable_query_strings']  修改成 false 这样就关闭了查询字符串形式 URL现在你的文件的路径就可以写得了,例如:http://localhost/nianyi_2011/user/user_point就相当于先前没有配置的路由: http://localhost/nianyi_2011/ index.php ?c=user&m=user_point 同样如果后面有参数的话,只用往后一次累加就好的了。请注意:有时候我们这样写之后样式文件加载进来会有问题,找不到js  css  images等等目录,我们可以配置文件config.php里面设置$config['base_url'] = 'http://localhost/2011_11_cms/';站点的目录,接着我们在view模板文件<head></head>之间添加<base href="<?=base_url()?>" />,这样就能加载其他的文件的了
原创粉丝点击