【问题标题】:CI on EC2 is giving 404 on all requestsEC2 上的 CI 对所有请求都给出 404
【发布时间】:2014-03-20 01:39:00
【问题描述】:

我不知道是因为我编写的 $routes[] 配置还是任何原因,只是将 CI 放入服务器带来的欢迎消息很好。这甚至不适用于 .htaccess 我导致删除 htaccess 也会导致任何请求的 404。 我在 app 文件夹和系统文件夹中有这个 .htaccess

  RewriteEngine On
  RewriteBase /
  RewriteCond $1 ^(application|system|private|logs)
  RewriteRule ^(.*)$ index.php/access_denied/$1 [L]
  RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|resources|css|js|images)
  RewriteRule ^(.*)$ - [L]
  RewriteRule ^(.*)$ index.php/$1 [L]

并且根目录中的这个 .htaccess 重定向到维护索引并允许到当前的开发文件夹:

 RewriteEngine On
 RewriteCond %{REQUEST_URI} !(index.php|x-folder|ci2) [NC]
 RewriteRule ^ /index.php [L]

我的 route.php 看起来像这样:

   $route['default_controller'] = 'site/home';
   $route['404_override'] = '';

  /********** *********************Admin routes****************/
  $route['admin']='admin/user/login/' ;
  $route['admin/home']='admin/home' ;
  $route['admin/gallery']='admin/home/gallery' ;
  $route['admin/calendar']='admin/home/calendar' ;

并且在配置中我已将重要配置更改为:

  $config['base_url']= 'http://example.com.bd/';
  $config['index_page'] = '';

仅供参考:我在本地主机中的应用程序运行良好。 我在 EC2(Amazon) 上,当前的 php 版本是 5.2.3——codeigniter 很好地支持,mysql>5.5

我真的被困住了,谁能帮我离开这个地狱!?

【问题讨论】:

  • 你为什么将 default_controller 设置为一些干净的 url (site/home/)?它应该指向 home 是 home.php 的站点/主页
  • 确实,是的。已编辑!
  • 你能在这里看到什么吗?我该如何解决这个问题?
  • 成功了吗?你还在用 404 吗?
  • @MohammedAshiq 不..不,我的意思是我从一开始就拥有它的站点/主页,我只是在问题上打错了..此外,CI 避免了斜杠。无论如何,我的路线中都没有。你有什么建议吗?

标签: php mysql .htaccess codeigniter amazon-ec2


【解决方案1】:

正如 Sean 提到的,默认情况下 EC2 将 AllowOverride 设置为 None,这会禁止您的 .htaccess 运行。我的是一台 AMI 机器,以下是我在终端上运行它所遵循的步骤。

  1. sudo nano /etc/httpd/conf/httpd.conf
  2. 寻找<Directory "/var/www/html">
  3. 将“AllowOverride none”编辑为“AllowOverride all”
  4. 按“ctrl+o”、“enter”和“ctrl+x”退出。
  5. sudo 服务 httpd 重启

希望对你有帮助。

【讨论】:

  • 你刚刚救了我的命!
【解决方案2】:

似乎这个问题的答案应该是删除配置中的尾随“/”

$route['default_controller'] = 'site/home';

并将默认控制器重命名为 home.php

我猜 htaccess 似乎是正确的。并且应该可以工作。

删除路由 url 值中的所有尾部斜杠。例如 $route['admin'] 在登录后有一个斜杠,如“login/”。仅当您传递了一个 get 变量时才使用它们。例如,

$route['view-page/(:num)'] = "admin/admin/view_page/$1";

你可以在哪里得到这个变量

public function view_page(page_number){
    // your super code goes here!
}

我想这就是你面临的问题。

------------更新----

确保首先启用 mod_rewrite.c

# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change yourdomain.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$ 
# Change 'x-folder' to be the directory your codeigniter is residing. 
RewriteCond %{REQUEST_URI} !^/x-folder/ 
# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Change 'x-folder' to be the directory your codeigniter is residing. 
RewriteRule ^(.*)$ /x-folder/$1  
# Change yourdomain.com to be your domain again. 
# Change 'x-folder' to be the directory you will use for your main domain 
# followed by / then the main file for your site, Ive used index.php. 
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$  
RewriteRule ^(/)?$ x-folder/index.php [L]

把它放在 .htaccess 中,位于 /var/www/html .. 让我们试一试

【讨论】:

  • 我已经改变了一些有斜线但它仍然是 404!
【解决方案3】:

默认情况下,EC2 上的 AMI 实例将在您的 httpd.conf 中的 <Directory "/var/www/html"></Directory> 中设置 AllowOverride None。如果将其更改为 AllowOverride All,它将允许 Apache 使用 CodeIgniter 目录中的 .htaccess 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多