无法从URL中删除index.php

时间:2017-07-16 22:03:09

标签: codeigniter codeigniter-3

我正在尝试从URL中删除index.php,但我一直收到错误404。 配置文件:

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

这是我的.htaccess文件:

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

3 个答案:

答案 0 :(得分:2)

您的应用程序文件夹中还需要一个.htaccess文件,以下是该文件的详细信息:

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

答案 1 :(得分:1)

请将以下代码复制并粘贴到htaccess文件中并将其放入根文件夹和应用程序文件夹

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

答案 2 :(得分:0)

打开config.php并执行以下替换

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

$config['index_page'] = ""

只需替换

$config['uri_protocol'] ="AUTO"

$config['uri_protocol'] = "REQUEST_URI"

AND IN HTACCESS FILE下面的代码

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