对于 GET 请求找不到 angularjs 苗条的 404


angularjs slim 404 not found for GET request

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

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

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

结构如下:

  • /public_html/
    • 索引.html
    • 样式 : CSS
    • 视图 : 查看部分 .html
    • 脚本 : AngularJS 控制器
    • 应用程序接口
      • 索引.php
      • .htaccess #1
      • 供应商
        • 自动加载.php
        • 苗条
          • 苗条
            • 索引.php
            • .htaccess #2
            • 苗条
              • 苗条的 php 文件,例如路由.php
        • 还有很多其他的目录,例如塞巴斯蒂安,教义...
      • 测试
      • src : 示例 API
.htaccess #1 如下所示:
 RewriteEngine On    
 RewriteCond %{REQUEST_FILENAME} !-f    
 RewriteCond %{REQUEST_FILENAME} !-d    
 RewriteRule ^ index.php [QSA,L]    

第一个索引.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]

第二个索引.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."}

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

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

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

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

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