2017-04-07 218 views
1

更新, 我在Ubuntu服務器上部署codeigniter項目時出現了一些問題,當我點擊鏈接時,出現404 Apache錯誤。如何爲apache服務器設置codeigniter?

當我把項目放在http://roy.my-domain.com/ =/var/www/html /文件夾中時,它的工作正常 - 但是當我添加子目錄http://roy.my-domain.com/roy/ =/var/www/html/roy /時,我得到了404錯誤。

當我的網址是http://roy.my-domain.com/roy/index.php/about - 我得到codeigniter 404錯誤,而不是apache2。

錯誤:

未找到

請求的URL的index.php在此服務器上找到。

的Apache/2.4.18(Ubuntu的)在roy.my-domain.com端口80

這裏服務器是我的設置:

0。在Apache中檢查重寫mod - 得到「模塊重寫已啓用」

1。 我的項目在/ var/www/my-project/

2。 在包含以下內容: 應用 系統 的public_html 的index.php htaccess的

  • .htaccess文件:

    < IfModule mod_rewrite.c > RewriteEngine On RewriteBase/html/my-project/ RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}! -d

    #重寫所有其他URL的index.php/URL重寫規則 ^(。*)$的index.php?URL = $ 1 [PT,L]

    </IfModule>配置 < IfModule!mod_rewrite的.C> 的ErrorDocument 404的index.php </IfModule>配置

  • Apache2的。CONF:

    <目錄/ var/WWW /> 選項指標的FollowSymLinks 要求所有授予 < /目錄>

    <目錄/ var/www/html等/> 選項指標的FollowSymLinks 的AllowOverride所有 要求全部授予 </Directory>

  • config.php:

    $ config ['base_url'] ='http://roy.my-domain/my-project/'; $ config ['index_page'] =''; $ config ['uri_protocol'] ='AUTO';

  • 在index.php:

    $ system_path = '系統'(不../system和../application工作); $ application_folder ='application';

  • 的控制器:

    (笨默認視圖)的welcome.php About_Controller.php

  • 的觀點: (笨默認視圖)welcome_message.php about.php

  • 本地 - 一切正常。 ..Thanks

    +0

    您能否提供Apache錯誤日誌? – Viktor

    +0

    嗨,感謝 - 從Apache服務器沒有錯誤 - 我無法查看除主頁以外的任何頁面 - 當點擊鏈接 - 我得到'頁面無法顯示'錯誤 – RoyBarOn

    +0

    Viktor - 我已經設置$ config [' index_page'] ='';現在我得到一個錯誤 - 我更新我的帖子與錯誤內容 – RoyBarOn

    回答

    3
    <Directory /var/www/> 
           Options Indexes FollowSymLinks MultiViews 
           AllowOverride All 
           Order allow,deny 
           allow from all 
    </Directory> 
    

    的.htaccess:

    RewriteEngine On 
        RewriteBase /html/project/ 
    
        RewriteCond %{THE_REQUEST} \s/+(.*?)/{2,}([^\s]*) 
        RewriteRule^%1/%2 [R=302,L,NE] 
    
        RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)/{2,}[?\s] [NC] 
        RewriteRule^/%1/ [L,R=301] 
    
        RewriteCond %{HTTP_HOST} !^www\. [NC] 
        RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
    
        RewriteCond %{REQUEST_URI} system|application 
        RewriteRule ^(.*)$ index.php?/$1 [L] 
    
        RewriteCond %{REQUEST_FILENAME} !-f 
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteRule ^(.*)$ index.php?/$1 [L] 
    

    試試這個配置,不要忘了重裝了Apache。

    1

    設置CodeIgniter的一個簡單步驟。

    1. 下載並解壓你的CodeIgniter public_html或var/www/project你的域指向。
    2. 將您的項目打開爲URL:https://example.com/project。如果您獲得歡迎CodeIgniter消息,則必須成功安裝CodeIgniter。

    3. 確保在您的服務器上啓用了mod_rewrite。

    4. 在database.php中>通過您的憑據
    5. 寫代碼在.htaccess從URL刪除的index.php:
    <IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L] 
    </IfModule> 
    

    我認爲這將是對整個過程設置項目。確保在服務器上啓用mod_rewrite。由於

    +0

    靜態鏈接無法顯示 - 可能在config.php中有錯誤我將base_url配置爲http://mysite.domain.com並將index_page配置爲index.php – RoyBarOn

    +0

    對於base_url ..您必須設置$ confi [' base_url'] =「http://mysite.domain.com」.. \ –

    +0

    還有一件事...你的鏈接是否與index.php一起工作 –

    1

    這個錯誤可以通過觸發以下幾點:

    • 服務器配置錯誤(httpd.conf文件)

    • 的.htaccess發出

    • 的mod_security或類似

      1. 將你的項目上傳到「var/www/my_project」 。

      2. 在配置文件中:
        $config['base_url'] = '';
        $config['index_page'] = '';

      3. 這段代碼添加到您的.htaccess文件刪除index.php文件,並把這個.htaccess文件在主文件夾。

        <IfModule mod_rewrite.c> 
            RewriteEngine On 
        
            RewriteCond %{REQUEST_FILENAME} !-f 
            RewriteCond %{REQUEST_FILENAME} !-d 
        
            # Rewrite all other URLs to index.php/URL 
            RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 
        
            </IfModule> 
            <IfModule !mod_rewrite.c> 
             ErrorDocument 404 index.php 
            </IfModule> 
        

    而且Set AllowOverride to All在httpd.conf

    設置上/緩存文件夾的正確權限,而不是僅僅使該文件夾可寫的,你需要使它禁起來寫。

    我希望它能爲你工作。

    +0

    Jay Kareliya - 謝謝 - 但現在我無法訪問該網站 - 當我去http://my_site.my_domain.com/my_project - 它的重定向我到www.my_site.my_domain.com/my_project - 任何想法爲什麼? – RoyBarOn