CSS File not loading into PHP Laravel application with Google App Engine and runtime php72

跟風遠走 提交于 2021-01-29 13:02:22

问题


I try to run a standard installation of a Laravel 5.8.x application with its own CSS file on the Google App Engine with standard configuration (runtime: php72). The page is displayed, but the CSS file public/css/main.css is not loaded. There is a 404 error in the browser.

This is my app.yaml code:

runtime: php72
service: default

env_variables:
  APP_KEY: xxxxx
  APP_STORAGE: /tmp
  VIEW_COMPILED_PATH: /tmp
  APP_ENV: production
  APP_DEBUG: false
  CACHE_DRIVER: database
  SESSION_DRIVER: database
  ...

I added this line to welcome.blade.php into the head.

<link rel="stylesheet" href="/css/main.css">

How can I solve this problem?


回答1:


I had to add the following to your app.yaml file before env_variables:

handlers:
- url: /(.*\.(gif|png|jpg|css|js))$
  static_files: public/\1
  upload: public/.*\.(gif|png|jpg|css|js)$

- url: /.*
  secure: always
  redirect_http_response_code: 301
  script: auto

Then it works




回答2:


You should use the

asset()

function in laravel in order to define css and js files .

<link rel="stylesheet" href="{{asset('css/main.css')}}">

Try this . If you have any issue , let me know .



来源:https://stackoverflow.com/questions/57821824/css-file-not-loading-into-php-laravel-application-with-google-app-engine-and-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!