摸索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的定义:
- FollowSymLinks
- The server will follow symbolic links in this directory.
- Even though the server follows the symlink it does not change the pathname used to match against <Directory> sections.
- Note also, that this option gets ignored if set inside a <Location> section.
因此,我们需要在.htaccess中进行设定:Options FollowSymLinks
再试。ok。
全部的.htaccess文件如下:
- RewriteEngine on
- Options FollowSymLinks
- RewriteCond $1 !^(index\.php|images|robots\.txt)
- RewriteRule ^(.*)$ /index.php/$1 [L]



#1