问题
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