.htaccess 问题

摸索codeigniter。一开始就遇到了挫折。

按官方的提示,我想把RUL中的index.php隐藏掉。原来的URL是“www.your-site.com/index.php/news/article/my_article

通过设置.htaccess文件可以掩藏它。使用“非”(!)方法使指定以外的任何请求都重新定向。

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

在上面的例子中,任何除开 index.php,images,和robots.txt 的 HTTP 请求都当成对 index.php 文件的请求。

淡水照做了。但是给我的结果是:

Forbidden

You don't have permission to access /main on this server.


Apache/2.0.59 (Win32) DAV/2 PHP/5.2.3 Server at localhost Port 80

 

本以为是权限的问题,其实不是,而是由于Server的httpd.conf中将FollowSymLinks禁止了,也就是禁止了符号链接。来看看Apache Document中对FollowSymLinks的定义:

XML/HTML代码
  1. FollowSymLinks   
  2. The server will follow symbolic links in this directory.    
  3. Even though the server follows the symlink it does not change the pathname used to match against <Directory> sections.   
  4. Note also, that this option gets ignored if set inside a <Location> section.  

因此,我们需要在.htaccess中进行设定:Options FollowSymLinks

再试。ok。

全部的.htaccess文件如下:

XML/HTML代码
  1. RewriteEngine on   
  2. Options FollowSymLinks   
  3. RewriteCond $1 !^(index\.php|images|robots\.txt)   
  4. RewriteRule ^(.*)$ /index.php/$1 [L]  

Tags: .htaccess, codeigniter

« 上一篇 | 下一篇 »

只显示10条记录相关文章

Trackbacks

点击获得Trackback地址,Encode: UTF-8 点击获得Trackback地址,Encode: GB2312 or GBK 点击获得Trackback地址,Encode: BIG5

3条记录访客评论

哈哈,淡水兄,我这也有一个,好像更安全点。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

Post by cain on 2008, May 13, 4:13 PM 引用此文发表评论 #1

引用 Hex 说过的话:
看到楼主比较喜欢 CodeIgniter,所以特邀请参观访问 CodeIgniter 中国官方网站! http://codeigniter.org.cn
一直很关注,哈哈。

Post by 淡水河边 on 2008, January 17, 9:06 AM 引用此文发表评论 #2

看到楼主比较喜欢 CodeIgniter,所以特邀请参观访问 CodeIgniter 中国官方网站! http://codeigniter.org.cn

Post by Hex on 2008, January 16, 11:21 AM 引用此文发表评论 #3


发表评论

评论内容 (必填):