2017-10-06 135 views
1

我正在codeigniter 3.1.6上工作。Codeigniter 3.1.6 - 如何從url中刪除index.php

我添加了.htaccess文件。 我也將base_url路徑更改爲我的項目路徑,從index_page中刪除index.php,並將url_protocol更改爲REQUEST_URI

儘管我將url重定向到任何控制器方法,但它將錯誤報告爲'The page you requested was not found'。

我也搜索和應用不同的.htaccess,但它不工作。 如果我在base_url結尾添加/index.php,那麼它的工作,但它的錯誤。它應該工作沒有index.php。只有3.1.6給這個問題。

注:笨-3.1.4正常工作只有這個版本是給一個問題

+2

[笨3取出的index.php問題]的可能的複製(https://stackoverflow.com/questions/20169545/codeigniter-3-remove-index-php-problems) –

+0

但不工作,根據那些迴應。這就是爲什麼我在這裏發佈 –

+0

試試這個問題的答案。然後讓我知道我會幫你確定的。 –

回答

1

更改文件夾名稱CodeIgniter-3.1.6ci

設置你base_url

$config['base_url'] = 'http://localhost/ci/ 

使用此.htaccess

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

令人敬畏的兄弟,它的工作原理。但這一切還在繼續?死於缺少'RewriteBase/ci'?對於其他版本,我還沒有使用這樣的線仍然他們工作正常?怎麼樣? –

0

1)編輯的config.php

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

$config['index_page'] = '’; 

2)創建/編輯.htaccess文件

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

不工作bro。已經做到了。只有這個版本給出了一個問題。我第一次使用這個版本 –

2

使用這個腳本在.htaccess

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading 
    # slashes. 
    # If your page resides at 
    # http://www.example.com/mypage/test1 
    # then use 
    # RewriteBase /mypage/test1/ 
    RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system) 

    RewriteRule ^(.*)$ index.php?/$1 [L] 
    # If your root folder is at /mypage/test1/ 
    RewriteRule ^(.*?)$ /mypage/test1/index.php?/$1 [L] 

</IfModule> 

<IfModule !mod_rewrite.c> 
# If we don't have mod_rewrite installed, all 404's 
# can be sent to index.php, and everything works as normal. 
# Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 

刪除index.phpconfig.php $config['index_page'] = '';

+0

不工作@星期日 –