2017-02-25 118 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'] = '';