2013-05-27 37 views
2

填充和提交此表格後:URL未找到(笨應用在Amazon EC2)

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>My App</title> 
</head> 
<body> 
    <?php echo validation_errors(); ?> 
    <?php echo form_open('search'); ?> 
     <p> 
      <input type="input" name="username" placeholder="@UserName" /> 
      <input type="submit" name="submit" value="Search" /> 
     </p>   
    </form>  
</body> 
</html> 

我提交的數據被首先處理,並且用戶應該被重定向到search_page3.php。相反,我得到這個錯誤:

Not Found

The requested URL /search was not found on this server.

Apache/2.2.24 (Amazon) Server at ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com Port 80

這裏是我的控制器:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
class Search extends CI_Controller { 
    public function index() 
    {   
     $this->load->helper('form'); 
     $this->load->library('form_validation'); 

     // ... 

     $this->form_validation->set_rules('username', 'username', 'required'); 
     $username = $this->input->post('username'); 

     if($this->form_validation->run() === FALSE || $this->val_username($username) === FALSE) 
     { 
      $this->load->view('search_page2'); 
     }  
     else 
     { 
        // process this data    
      // ... 

      $data['data'] = $data;  
      $this->load->view('search_page3', $data);      
     }    
    } 
    // additional helper functions 
    // ... 
} 
/* End of file search.php */ 
/* Location: ./application/controllers/search.php */ 

我在this answer是胡安·卡洛斯·通過設定的public_html到AllowOverride解決All他URL問題閱讀。 爲了安全起見,我的問題是,我該如何解決我的錯誤?

這是我的基本網址從我的笨application/config/config.php文件:

$config['base_url'] = 'http://xxx-xx-xxx-xxx-xxx.compute-1.amazonaws.com/'; 

這是我httpd.conf從我的EC2實例:

# Each directory to which Apache has access can be configured with respect 
# to which services and features are allowed and/or disabled in that 
# directory (and its subdirectories). 
# 
# First, we configure the "default" to be a very restrictive set of 
# features. 
# 
<Directory /> 
    Options FollowSymLinks 
    AllowOverride None 
</Directory> 

# 
# Note that from this point forward you must specifically allow 
# particular features to be enabled - so if something's not working as 
# you might expect, make sure that you have specifically enabled it 
# below. 
# 

# 

,這裏是我的.htaccess文件位於/var/www/html

RewriteEngine On 

# Put your installation directory here: 
# If your URL is www.example.com/, use/
# If your URL is www.example.com/site_folder/, use /site_folder/ 

RewriteBase/

# Do not enable rewriting for files or directories that exist 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# For reuests that are not actual files or directories, 
# Rewrite to index.php/URL 
RewriteRule ^(.*)$ index.php/$1 [PT,L] 
+1

你可以顯示窗體('form_open'部分)的html部分的源代碼嗎? – itachi

+0

+1 form_open()是一個內置的CodeIgniter表單助手,包含幫助處理表單的函數。 http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html – Anthony

回答

2

http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride

如果AllowOverride設置爲None,該.htaccess文件被完全忽略。因此,index.php將不會被重寫。嘗試設置form_openform_open('index.php/search');進行確認。

編輯httpd.conf並將AllowOverride None更改爲AllowOverride All並重新啓動httpd。另外,僅供參考,您沒有重定向到search_page3.php,您正在根據一組條件加載特定的視圖。當你說「重定向」時,我尋找redirect('somepage');

+0

+1 Hi stormdrain。感謝您的回覆。我改變了'form_open('search');'form_open('index.php/search');'和我的視圖search_page3.php確實在加載(但我在search_page3.php上有幾個PHP未定義的屬性錯誤,但至少它加載了)!但是,當我回到'form_open('search');並將httpd.conf編輯爲'AllowOverride All'並重新啓動httpd'httpd -k restart',然後重新加載頁面,現在我得到一個空白頁面。當我再次返回form_open('index.php/search')時,查看加載錯誤的search_page3.php。 – Anthony

+0

順便說一句,昨天,我設置權限爲 'chmod 777/var/www/html -R' – Anthony

+1

chmod 0755可能是一個更理智的設置(777賦予執行權限,這在文檔根目錄中並不是你想要的) 。你正在根html文件夾中工作正確嗎?即你不在/ var/www/html/codeigniter而是在/ var/www/html – stormdrain