【问题标题】:Cannot include js and css file in google cloud app无法在谷歌云应用中包含 js 和 css 文件
【发布时间】:2015-11-04 21:46:36
【问题描述】:

我正在使用 Lamp 部署,使用 Cloud sql。将我的项目上传到 xxx.appspot.com 后。所有的 css 和 js 文件都没有打开。它抛出:

错误:未找到请求的 URL /public/js/admin/custom.js 不是 在此服务器上找到。

我添加css文件如下:

<link rel="stylesheet" href="http://syncspot-ds.appspot.com/public/css/admin/login.css">
<link rel="stylesheet" href="http://syncspot-ds.appspot.com/public/css/admin/bootstrap.css">
<link rel="stylesheet" href="http://syncspot-ds.appspot.com/public/css/admin/font-awesome.css">

我的 app.yaml 文件如下:

application: xxx
version: 1
runtime: php55
api_version: 1
threadsafe: true

handlers:

- url: /public/css/admin
  static_dir: /public/css/admin

- url: /public/css/front
  static_dir: /public/css/front

- url: /public/css/front/images
  static_dir: /public/css/front/images

- url: /public/fonts
  static_dir: /public/fonts

- url: /public/images
  static_dir: /public/images

- url: /public/images/00-ICON LOGO
  static_dir: /public/images/00-ICON LOGO

- url: /public/images/admin
  static_dir: /public/images/admin

- url: /public/images/background
  static_dir: /public/images/background

- url: /public/images/icons
  static_dir: /public/images/icons

- url: /public/images/logo
  static_dir: /public/images/logo

- url: /public/js/admin
  static_dir: /public/js/admin

- url: /public/js/front
  static_dir: /public/js/front

- url: /public/js/gmap
  static_dir: /public/js/gmap

- url: /public/swf
  static_dir: /public/swf

- url: /public/uploads/channel_content
  static_dir: /public/uploads/channel_content

- url: /public/uploads/profile_img
  static_dir: /public/uploads/profile_img 

- url: /.*
  script: index.php

我的 .htaccess 文件如下:

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|public|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

我正在使用 Code Igniter、AngularJS 和 MySql。如果我使用外部 css 说:

 <link rel="stylesheet" href="http://1223.123.123.123/xxx/public/css/admin/login.css">

它工作正常。

请帮助我,以便我可以链接到 css 或 js 文件。

【问题讨论】:

    标签: angularjs .htaccess google-app-engine cloud google-cloud-storage


    【解决方案1】:

    对于静态目录,documentation 在 static_dir 部分中没有前导“/”。

    尝试使用这种格式:

    - url: /public/css/admin
      static_dir: public/css/admin
    

    【讨论】:

    • 为什么不把整个公共目录设为静态呢?那么你就不需要所有这些配置了。
    猜你喜欢
    • 1970-01-01
    • 2015-06-18
    • 2018-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多