2017-02-25 158 views
2

我很努力去除我的CodeIgniter URL的'index.php'部分。 我正在使用CodeIgniter版本3.1.2。我已经按照有关其他问题的所有步骤一下:从CodeIgniter URL中删除index.php

  • 改变$config['index_page'] = 'index.php'$config['index_page'] = ''
  • 改变$config['uri_protocol'] = 'AUTO'$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]

然而,当我尝试访问我的网站,我得到的以下错误代码。

未找到

所请求的网址/ Toneel /网站/指数在此服务器上未找到。

重写模块在我的Apache服务器中打开。 任何人都可以帮我解决这个问题吗?

+0

RewriteEngine叙述后添加RewriteBase/your_project_name在本地主机,只是RewriteBase /运行时,当你的代码上传到服务器上。 – Omi

回答

4

此设置为我工作。

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

的.htaccess

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    #RewriteBase/

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [QSA,L] 
</IfModule> 

要允许在Apache的配置压倒一切htaccess你必须编辑和更改/apache2.conf文件

AllowOverride All 

,并重新启动服务器。

+0

我认为AllowOverride All是问题。我将其更改为全部,错误从“未找到”更改为:禁止 您无权访问此服务器上的/ Toneel/Site/index。 – Yaniiick

+0

我的Apache错误日志声明如下:'选项FollowSymLinks和SymLinksIfOwnerMatch都关闭,所以RewriteRule指令也被禁止,因为它有类似的能力来规避目录限制' – Yaniiick

+0

您正在使用的操作系统? – Goran

1

试试这个代码.htaac​​ess:

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

谢谢你的回答,但是这段代码给出了相同的错误结果。我试过每个可能的.htaccess代码,我可以找到它们都没有工作 – Yaniiick

+0

重写模块打开后,你重新启动服务器@Yaniiick –

0

在.htaccess文件

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

试试这个对我来说,它的工作原理与:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /project-name 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [QSA,L] 
</IfModule> 

**重要,这应该是一个.htaccess文件中的根你项目。

配置应该是这样的:

$config['base_url'] = 'http://your-url-here/'; 
$config['index_page'] = '';