codeigniter中的.htaccess问题,用于从url中删除index.php

时间:2014-12-19 10:30:01

标签: .htaccess codeigniter

我的根目录中有.htaccess个文件:

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

如果我使用
http://iemedica.com.ph/index.php/aboutUs它会为我工作  但如果我使用
http://iemedica.com.ph/aboutUs它给我404错误

4 个答案:

答案 0 :(得分:1)

将.htaccess更改为:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteRule ^(.+)$ index.php?/$1 [L,QSA]

同样在DocumentRoot/application/config/config.php中,您需要拥有以下配置设置:

$config['base_url']     = '';
$config['index_page']   = '';
$config['uri_protocol'] = 'AUTO';

答案 1 :(得分:0)

首先,您在application-> config-> config.php

中进行以下更改
             $config['base_url'] = "";
             $config['index_page'] = "";

在.htaccess中编写以下代码。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php/$0 [PT,L]

这样可行。

答案 2 :(得分:0)

试试这个:)

<IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
   RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

答案 3 :(得分:0)

在Apache服务器中启用Rewrite模块并使用此HTA Access

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

复制并粘贴此代码,并将该文件保存在codeigniter目录下的.htaccess名称中。