在网络服务器上使用.htacces Codeigniter

时间:2016-11-18 08:38:55

标签: php apache .htaccess codeigniter

我有代码.htacces在您使用Codeigniter时很熟悉

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

但它没有用。像这样。 enter image description here  当我删除这个.htacces时,代码运行良好。我已经检查了apache上的mod_rewrite是否启用。我很困惑,请帮忙

3 个答案:

答案 0 :(得分:1)

尝试这个

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /projectname
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

注意:projectname是您的根文件夹名称

答案 1 :(得分:1)

即使您启用了mod_rewrite,仍然有一个设置可以阻止.htaccess工作。

检查您的 httpd.conf 文件,并确保在目录设置中

AllowOverride None

更改为

AllowOverride All

如果您需要更多详细信息,请询问!我已经非常简短了。

答案 2 :(得分:1)

在.htaccess

中试试
RewriteEngine on
RewriteBase /ci
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

并在application / config / config.php

$config['index_page'] = ''; // make it empty.