2015-03-19 99 views
1

我測試了我的網站很多次,但我無法解析Page not found錯誤。 井,Codeigniter視圖可用,但仍然收到頁面​​未找到錯誤

1步驟:創建一個控制器和所謂welcomelogin.php - 其中I存儲兩個功能

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
class WelcomeLogin extends CI_Controller { 
public function index() 
{ 
    $this->home(); 
} 
public function home(){ 

    $this->load->helper('url'); 
    $this->load->view('login'); 
} 

public function inside(){ 
    $this->load->helper('url'); 
    $this->load->view('inside');  
} 

2-步驟:以我rote.php文件I簡單執行follwing:

$route['default_controller'] = "welcomeLogin"; 
$route['404_override'] = ''; 

3步:內部視圖文件夾我創建兩個文件一個是login.php &第二是inside.php與login.php包含登錄窗體和inside.php包含簡單的HTML。

現在我得到了登錄頁面,我的網站的主頁面是工作的罰款: http://localhost/website/Codeigniter_Project/MyProject/

當我做下面我得到找不到網頁錯誤: 我試着用兩種方式無一不給了我同樣的錯誤:

1-ST的方式:通過直接捐贈視圖名稱和結果頁面沒有找到 本地主機/網站/ Codeigniter_Project/MyProject的/內

2擋的方式:通過給控制器的名稱,然後查看,但結果頁面未找到 本地主機/網站/ Codeigniter_Project/MyProject的/ welcomelogin(controllername)/內

請幫助我,因爲我通過搜索和應用不同的答案花了近2小時,是有堆棧類似的問題和一些有我已經嘗試過的答案但沒有工作&那些問題是有點不同,那麼我的。感謝您的時間夥計。:)我在本地主機服務器上運行,並且我的apache mod_rewrite已打開。謝謝。 &我是新來的笨感謝

我的.htaccess文件:

<IfModule mod_rewrite.c> 

    RewriteEngine On 
    RewriteBase /website/Codeigniter_Project/MyProject/ 


    # Removes trailing slashes (prevents SEO duplicate content issues) 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.+)/$ $1 [L,R=301] 

    # Enforce www 
    # If you have subdomains, you can add them to 
    # the list using the "|" (OR) regex operator 
    RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC] 
    RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301] 

    # Enforce NO www 
    #RewriteCond %{HTTP_HOST} ^www [NC] 
    #RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301] 

    ### 

    # Removes access to the system folder by users. 
    # Additionally this will allow you to create a System.php controller, 
    # previously this would not have been possible. 
    # 'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php/$1 [L] 

    # Checks to see if the user is attempting to access a valid file, 
    # such as an image or css document, if this isn't true it sends the 
    # request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L] 

</IfModule> 

<IfModule !mod_rewrite.c> 

    # Without mod_rewrite, route 404's to the front controller 
    ErrorDocument 404 /index.php 

</IfModule> 
+0

什麼BASE_URL? – Arun 2015-03-19 04:47:21

+0

inside - 不工作 – user2268488 2015-03-19 04:52:50

回答

0

請這個網址嘗試

http://localhost/website/Codeigniter_Project/MyProject/index.php/inside 

希望這個如果你沒有限制url.htaccess流將工作

+0

嗨不工作,我的.htaccess文件包含:拒絕所有你認爲我應該改變那裏,如果是的話,那麼你能否提供我的代碼,因爲不知道可能會有什麼。謝謝 – user2268488 2015-03-19 05:11:06

+0

@ user2268488,我使用http://www.farinspace.com/codeigniter-htaccess-file/中的'htaccess'。它包含您需要的所有必要信息:) – Arun 2015-03-19 05:13:39

+0

嗨兄弟,我實現了我的.htaccess文件與上面,它似乎不工作,因爲我試圖通過給予控制器名稱/方法名稱,其中方法名稱包含$ this-> load-> view (),但仍然不工作:( – user2268488 2015-03-19 05:26:57

0

PHP配置代碼似乎很好,你應該檢查.htaccess文件,

當你添加.htaccess文件有問題,你應該從你的web目錄添加RewriteBase到項目主頁,請參見下面的示例代碼

RewriteBase /website/Codeigniter_Project/MyProject/ 

更新htaccess文件

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    ########### TODO: deploying on subdir must rewrite this 
    RewriteBase /website/Codeigniter_Project/MyProject/ 

    #Removes access to the system folder by users. 
    #Additionally this will allow you to create a System.php controller, 
    #previously this would not have been possible. 
    #'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #When your application folder isn't in the system folder 
    #This snippet prevents user access to the application folder 
    #Submitted by: Fabdrol 
    #Rename 'application' to your applications folder name. 
    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

    # you could simply throw this into an htaccess file the directory you want displayed 
    Options -Indexes 

</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> 
+0

嗨兄弟你可以告訴我,我必須把我的控制器名稱放在.htaccess文件中:#如果你的默認控制器不是 #「welcome」,你應該改變這個 RewriteRule ^(welcome(/ index)?| index( \/$/[L,R = 301] – user2268488 2015-03-19 05:34:53

+0

因此,而不是歡迎(/索引)是否必須替換我的控制器名稱welcomelogin小或上限,因爲我有類WelcomeLogin – user2268488 2015-03-19 05:36:06

+0

好吧,在.htaccess中刪除'### Canonicalize codeigniter URLs'部分,ci路徑自動檢測它......並且命名約定可能會影響os版本,您可以在這裏閱讀更多內容https://ellislab.com/codeigniter/user-guide /general/styleguide.html – Girish 2015-03-19 05:40:27

0

沒有在我的情況下,只需要使用索引就可以進行任何修改。在路徑PHP文件,以便路徑應該是這樣的http://localhost/website/Codeigniter_Project/MyProject/index.php/welcomelogin/inside

我發現通過一個教程,我發現同時研究我的答案網上鍊接http://tutorialcodeigniter.com/beginners/creating-controller.html這個答案 - 對於如何從URL中移除的index.php。最好的解釋,併爲我工作 - 。Cannot remove index.php from CodeIgniter URL

但由於反正誰試圖幫助我爲查詢:)