关于lamp去掉index.php

6 篇文章 0 订阅
4 篇文章 0 订阅
一》在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()?>" />,这样就能加载其他的文件的了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值