0

我看了很多文章并尝试了不同的方法,但它仍然不起作用。

现在我的 URL 看起来像mysite.com/index.php/[controller]. 目标是mysite.com/[controller]

config.php中:

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

我的.htaccess文件包含

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

在我的 Apache 服务器中也启用了mod_rewrite

还有其他解决方案吗?

4

5 回答 5

1

In application/config/config.php

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

in .htaccess (Place Outside application folder)

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

Update 2018-02-27

$config['base_url'] = 'https://stackoverflow.com/'; # Must fill

else you get this error Codeigniter echoing [::1] instead of localhost

use this .htaccess

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

Refference

于 2015-08-03T10:54:41.763 回答
0

在你的配置文件中试试这个

$config['base_url'] = '';
$config['server_root'] = $_SERVER['DOCUMENT_ROOT'];
于 2015-08-02T10:44:26.053 回答
0

这个对我来说很好用,你可以试试这个

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
于 2015-08-02T10:49:54.080 回答
0

这对我有用[在linux 操作系统中]:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
于 2015-08-02T10:51:58.177 回答
0

在配置文件中使用你的项目 url 在 base_url

$config['base_url'] = 'http://localhost/project';
于 2015-08-02T12:34:05.883 回答