【问题标题】:angularjs slim 404 not found for GET request没有为 GET 请求找到 angularjs slim 404
【发布时间】:2015-08-20 09:39:05
【问题描述】:

我已经浏览了这里的相关帖子,但我似乎无法让我的应用程序正常工作。

我决定使用generator-angular-php 快速设置端到端应用程序。

当我使用 grunt serve 时,应用程序似乎按预期工作,所以我决定将它按原样放在我的 apache 服务器上。我用 grunt 构建它,并将 dist 文件夹中的文件复制到我的 /var/www//public_html/

结构如下:

  • /public_html/
    • index.html
    • 样式:CSS
    • 视图:查看部分 .html
    • 脚本:angularjs 控制器
    • API
      • index.php
      • .htaccess #1
      • 供应商
        • 自动加载.php
        • 苗条
          • 苗条
            • index.php
            • .htaccess #2
            • 修身
              • slim php 文件,例如 Route.php
        • 许多其他目录,例如。塞巴斯蒂安,学说...
      • 测试
      • src : 示例 API
.htaccess #1 如下所示:
 RewriteEngine On    
 RewriteCond %{REQUEST_FILENAME} !-f    
 RewriteCond %{REQUEST_FILENAME} !-d    
 RewriteRule ^ index.php [QSA,L]    

第一个 index.php 包含

<?php
error_reporting(-1);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
date_default_timezone_set('UTC');

try {

    // Initialize Composer autoloader
    if (!file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
        throw new \Exception('Composer dependencies not installed. Run `make install --directory app/api`');
    }
    require_once $autoload;

    // Initialize Slim Framework
    if (!class_exists('\\Slim\\Slim')) {
        throw new \Exception(
            'Missing Slim from Composer dependencies.'
            . ' Ensure slim/slim is in composer.json and run `make update --directory app/api`'
        );
    }

    // Run application
    $app = new \Api\Application();
    $app->run();

} catch (\Exception $e) {
    if (isset($app)) {
        $app->handleException($e);
    } else {
        http_response_code(500);
        header('Content-Type: application/json');
        echo json_encode(array(
            'status' => 500,
            'statusText' => 'Internal Server Error',
            'description' => $e->getMessage(),
        ));
    }
}

.htaccess #2 如下所示:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA]

第二个 index.php 包含 php 代码:

-Slim Framework and register its PSR-0 autoloader.
-Instantiate a Slim application
-Define the Slim application routes (get, post, put etc

在我的网站启用文件中,我有:

<VirtualHost *:80>
    ServerAdmin hanto899@myphpportfolio.com
    ServerName myphpportfolio.com
    ServerAlias www.myphpportfolio.com
    DocumentRoot /var/www/myPhpPortfolio/public_html
    ErrorLog /var/www/myPhpPortfolio/public_html/error.log
    CustomLog /var/www/myPhpPortfolio/public_html/access.log combined

    <Directory "/var/www/myPhpPortfolio/public_html">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

我已启用重写模块。

但是,当我在浏览器中打开我的网站时,我得到一个:

GET http://myphpportfolio.com/api/features 404 (Not Found)

响应:

{"status":404,"statusText":"Not Found","description":"Resource \/features using GET method does not exist."}

我没有以任何方式更改代码,并且由于它可以在 grunt serve 中工作,我猜它应该可以在没有任何更改的情况下工作(?) 这给了我更多的白发,我没有想法......我错过了什么!

【问题讨论】:

  • 你想出解决方案了吗?我使用 generator-angular-php 构建了一个应用程序,当我部署到我是管理员的服务器时,它可以工作。当我部署到共享的服务器时,它不会;所以我很好奇你想出了什么解决方案?

标签: php angularjs apache .htaccess


【解决方案1】:

检查复制文件的权限和所有权。

当 grunt 构建并创建最终目录时,它可能会更改 /dist 输出文件的权限和所有权。 chmod 755 -R 包含您网站的 html 目录,并可能更改所有者(root?)。

此外,这些生成器有时被配置为输出多个构建版本......一个用于测试,一个用于实时托管。

例如,grunt test 可能将图像输出到临时目录,而 grunt build 输出到 /dist/images。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 2018-06-07
    • 2019-08-01
    • 2020-08-15
    相关资源
    最近更新 更多