2012-12-01 112 views
2

htaccess我已经没有运行,为什么?codeigniter htaccess未加载?

有我的htaccess

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteRule ^(.*)$ index.php?/$1 [QSA,L] 
RewriteRule ^(.*)$ index.php?/$1 [QSA,L] 
php_value memory_limit "64M" 
</IfModule> 

和索引页配置

$config['index_page'] = ''; 

但仍有404页找不到

http://hostname/blog <=== 404 page not found 
http://hostname/index.php/blog <=== normal page show up 
+1

在重写规则行前面有一个“#”注释标记。为什么? –

+0

删除#或试试RewriteRule ^(。*)$ index.php?$ 1 [L] – alditis

+0

得到那个正斜杠^ index.php?/ $ 1 = index.php?$ 1 –

回答

1
RewriteRule ^(.*)$ index.php?/$1 [QSA,L] 

应该是:

RewriteRule ^(.*)$ /index.php/$1 [L] 

请参阅http://ellislab.com/codeigniter/user-guide/general/urls.html以及标题为'Removing the index.php file'的部分您需要使用相同的RewriteRule,但您所使用的RewriteCond并不错。

+0

RewriteEngine叙述在 的RewriteCond%{REQUEST_FILENAME}!-d 的RewriteCond%{REQUEST_FILENAME}!-f 重写规则^(。*)$ /的index.php/$ 1 [L] php_value memory_limit的“64M” 我已经 – h454n

+0

删除IfModule标签只是为了确保即使是在服务器启用了mod_rewrite。只是放在安全的一边,放一些随机垃圾文本,如文件中的dghdkhgksdhkg并保存。如果它没有500服务器错误的错误,那么你的htaccess文件甚至没有被读取。 –

+0

也改变了我的htaccess仍然没有找到404页:( –

0

在应用程序根目录中包含the.htaccess文件以及index.php文件。 (检查htaccess的扩展名是正确的,BZ htaccess.txt并没有为我工作。)

,并添加以下规则.htaccess文件,

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 

然后找到你的应用程序下面的行/ config/config.php文件

$config['index_page'] = 'index.php'; 

将变量设置为空,如下所示。

$config['index_page'] = ''; 

就是这样,它为我工作。

如果没有进一步的工作,尝试用这些参数( 'AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI' 和 'ORIG_PATH_INFO')逐一

$config['uri_protocol'] = 'AUTO'; 
0
替换以下变量
RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

这是用Codeigniter's user guide编写的标准内容,用于删除index.php文件,您可以在其中添加其他规则。

+0

我已经使用这种方法,但仍然无法工作 – h454n