用户
 找回密码
 入住 CI 中国社区
搜索
查看: 9103|回复: 17
收起左侧

[HELP] rewrite去掉index.php出现错误

  [复制链接]
发表于 2012-3-5 23:06:10 | 显示全部楼层 |阅读模式
apache已经开启了rewrite.利用phpinfo()查看模块里面也有mod_rewrite。但是我却出现500 Internal Server Error错误,求解!
代码均是按照hex的步骤进行的。项目根路径:http://localhost
/houtai/
没有修改之前:http://localhost/houtai/index.php/upload   正常访问
(1).htaccess:
RewriteEngine on   
RewriteCond $1 !^(index\\.php|images|robots\\.txt)   
RewriteRule ^(.*)$ /houtai/index.php/$1 [L]
(2)config.php中:
  $config['index_page'] = "";
然后:
http://localhost/houtai/upload访问,出现Internal Server Error这样的错误。
求解!!!
发表于 2012-3-5 23:59:06 | 显示全部楼层
php.ini 里的rewrite开启了吗?
发表于 2012-3-6 08:51:24 | 显示全部楼层
rewrite 确认开启  你用的APACHE
那么还有有权限访问.HTACESS  在目录/ 设置AllowOverride  All
Allow from all  这两个 .htacess 还的有访问权限 这样就可以了
 楼主| 发表于 2012-3-6 08:58:36 | 显示全部楼层
楼上的大哥,我在http.conf里面把AllowOverride 都设置成all了。网上说这种错误跟 rewrite规则写的不规范有关系,但是我都是按照HEX的代码写的啊???郁闷
 楼主| 发表于 2012-3-6 09:41:03 | 显示全部楼层
补充:就是出现这样的错误:Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, postmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request
发表于 2012-3-6 10:08:48 | 显示全部楼层
RewriteCond  里面不要把  application 什么的文件夹也列入进去吗?
发表于 2012-3-9 17:03:07 | 显示全部楼层
是你代码的问题吧...
 楼主| 发表于 2012-3-9 17:30:10 | 显示全部楼层
我的代码全在上面粘着呢,其它的代码还么有附加上啊---
发表于 2012-3-9 18:13:14 | 显示全部楼层
去掉CodeIgniter URL中的index.php

CI默认的rewrite url中是类似这样的,例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就类似这样http://localhost/CodeIgniter/index.php/welcome。不太好看,怎么把其中的index.php取掉呢?

1. 打开apache的配置文件,conf/httpd.conf :

LoadModule rewrite_module modules/mod_rewrite.so,把该行前的#去掉。

搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为AllowOverride All。

2. 在CI的根目录下,即在index.php,system的同级目录下,建立.htaccess,直接建立该文件名的不会成功,可以先建立记事本文件,另存为该名的文件即可。内容如下(CI手册上也有介绍):

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

如果文件不是在www的根目录下,例如我的是:http://www.nowamagic.net/CodeIgniter/,第三行需要改写为RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]。

另外,我的index.php的同级目录下还有js文件夹和css文件夹,这些需要过滤除去,第二行需要改写为:RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)

3.将CI中配置文件(system/application/config/config.php)中$config['index_page'] = "index.php";将$config['index_page'] = ""; 。

注意 第2条中的 如果有其他文件夹 也要卸载 rewrite 中
例如 application , system 等

点评

非常详细  发表于 2012-8-29 10:03
发表于 2012-3-11 02:20:59 | 显示全部楼层

RewriteCond $1 !^(index\\.php|images|robots\\.txt)
改成
RewriteCond $1 !^(index\.php|images|upload|robots\.txt)  
试下呢

本版积分规则