【问题标题】:404 Not Found: Deploying PHP app on Heroku404 Not Found:在 Heroku 上部署 PHP 应用程序
【发布时间】:2017-06-25 19:50:58
【问题描述】:

我正在尝试在 Heroku 上部署 PHP 应用程序,但遇到了问题。我的项目结构是这样的:

+main 
 +app
   +view (contains all my pages) 
 +public_html 
   + assets (contains css/js files) 
   -index.php 
-Procfile 
-composer.json
-.htaccess

index.php

<?php
// Grabs the URI and breaks it apart in case we have querystring stuff
$request_uri = explode('?', $_SERVER['REQUEST_URI'], 2);

$routes = array(
    "/" => "home",
    "/contact" => "contact",
    "/crew-search" => "crew-search",
    "/dashboard" => "dashboard",
    "/documentation" => "documentation",
    "/entry-list" => "entry-list",
    "/gallery" => "gallery",
    "/links" => "links",
    "/login" => "login",
    "/media" => "media",
    "/results" => "results",
    "/schedule" => "schedule",
    "/sponsors" => "sponsors"
);

if(isset($routes[$request_uri[0]])) {
  require '../app/view/'.$routes[$request_uri[0]].'.php';
} else {
  header('HTTP/1.0 404 Not Found');
  require '../app/view/404.php';
}

过程文件

web: vendor/bin/heroku-php-apache2 public_html/

.htaccess

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

尝试访问所有页面时出现错误消息。奇怪的是,这在 localhost 上运行良好。例如:

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

谢谢。

【问题讨论】:

  • 你没有.Htaccess?
  • 其他路线在heroku上工作?
  • 不,所有路线都不起作用。 @simon.ro
  • 它可以在你的开发机器上工作吗?我很困惑为什么你的 htaccess 在根目录中,但索引在 public_html 中,但没有重写来推送到 public_html?
  • 抱歉,刚刚读到它可以在本地工作,尽管我会冒险猜测您已经在本地设置了一个将 public_html 视为文档根目录的 hosts 文件?

标签: php heroku


【解决方案1】:

您的 htaccess 文件在错误的位置,尝试将其移动到 public_html ,它会工作。

【讨论】:

    猜你喜欢
    • 2015-05-20
    • 2013-02-20
    • 2018-10-22
    • 1970-01-01
    • 2018-02-02
    • 2015-11-22
    • 2022-01-07
    • 2014-07-17
    • 2018-10-22
    相关资源
    最近更新 更多