找不到URL(Amazon EC2上的CodeIgniter应用程序)

时间:2013-05-27 14:25:42

标签: php codeigniter 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 。相反,我收到了这个错误:

  

未找到

     

在此服务器上找不到请求的网址/搜索。

     

Apache / 2.2.24(亚马逊)服务器   ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com 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阅读Juan Carlos通过将public_html的AllowOverride设置为All来解决他的网址问题。 为了安全起见,我的问题是,我究竟如何解决错误?

以下是我的CodeIgniter application/config/config.php文件的基本网址:

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

这是我的EC2实例中的httpd.conf

# 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 个答案:

答案 0 :(得分:2)

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

如果AllowOverride设置为None,则.htaccess文件将被完全忽略。因此,index.php将不会被重写。尝试将form_open设置为form_open('index.php/search');进行确认。

修改httpd.conf并将AllowOverride None更改为AllowOverride All并重新启动httpd。

另外,仅供参考,您没有重定向到search_page3.php,而是根据一组条件加载特定视图。当您说“重定向”时,我会查找redirect('somepage');