I have set up a website using docusaurus which works great, but when I check the indexing status of my website on google, I got a lot of 'Discovered - currently not indexed' problems, which appears to be a routing problem.
The compiled version of the docusaurus website generates an 'index.html' file for every page or md file in the docusauus project in a separate folder, but the generated links don't add the 'index.html' and instead end like this: https://cam-inspector.com/contact. The browser doesn't seem to go to 'https://cam-inspector.com/contact/index.html', instead it uses the root index.html page and appears to handle the routing locally. This works for viewing, but the google crawler only gets to see the root, so every page contains a canonical url of 'https://cam-inspector.com'. When you browse directly to 'https://cam-inspector.com/contact/index.html', the correct file is retrieved from the server and the canonical tag is correct to 'https://cam-inspector.com/contact'.
I tried to add a redirect to the yaml file of the google app engine deployment so that it would add 'index.hmtl' to all routes that don't end with a file extension, but that doesn't seem to work:
handlers:
# for url without extensions, needs to go to index.html to get seo correct
- url: /(?:/|^)[^./]+$
static_files: www/\1/index.html
upload: www/(.*)/index.html
# files with extension, needed to get all the files
- url: /(.*\..+)$
static_files: www/\1
upload: www/(.*\..+)$
# Catch all handler to index.html, needed to get the root
- url: /.*
static_files: www/index.html
upload: www/index.html
In this post: app.yaml : Redirect any URL ending with / to {url}/index.html they appear to say that you can't add a redirect like that to the yaml def.
So now I'm a little stuck, the only thing I can think of is to add '/index.html' to all the links in the docusaurus code, but that sort of creates something very difficult and tricky to maintain (especially with the auto generated side bar of the docs, where it's much harder to change the links).
Any ideas on how to fix this?
found the solution:
use the following config in docusaurs.config.js: trailingSlash: true,
use these handlers in app.yaml:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)/$
static_files: www/\1/index.html
upload: www/(.*)
- url: /(.*)
static_files: www/\1
upload: www/(.*)
make certain you declare the links to your pages this way: \contacts\
then things start to behave as expected.
Here's my version of deploying a Docusaurus site to Google App Engine.
handlers:
# static files with a URL ending with a file extension
# (e.g. favicon.ico, manifest.json, jylade.png)
- url: /(.*\..+)$
static_files: build/\1
upload: build/(.*\..+)$
# index page
- url: /
static_files: build/index.html
upload: build/index.html
# anything that ends with a slash (e.g. /docs/)
- url: /(.*)/$
static_files: build/\1/index.html
upload: build/(.*)
# anything else (e.g. /docs)
- url: /(.*)
static_files: build/\1/index.html
upload: build/(.*)
Works for me with the default Docusaurus configuration.
It does not require trailingSlash: true.
Related
This React website is served on Google Cloud Platform
I want to edit an existing handler
- url: /(.*)$
static_files: public/\1/index.html
upload: public/.*/index.html
to get rid of warnings like this Static file referenced by handler not found: public/_ah/start/index.html
I have seen this solution, but I'm not quite sure how to use it in my case. Any ideas?
I tried option below, but it didn't work, build fails.
- url: /(?!.*\/_ah).*$
static_files: public/\1/index.html
upload: public/.*/index.html
An error in an application's app.yaml frequently causes the error static file referenced by handler not found. It basically means that one of app.yaml's static file handlers is diverting to a file that does not exist or is named wrongly.
You might be able to come up with a strategy if you have a technique of differentiating files from directories. You can achieve something like this by stating that all filenames must have extensions (and folders most not. in their names):
/optional/path/folder/ - serve index.html inside
- url: /(.*)/
static_files: public/\1/index.html
upload: public/.*/index.html
/optional/path/name.extension => files - serve them
- url: /((.*\/)*[^\/]+\.[^\/]+)$
static_files: public/\1
upload: public/.*
anything else is a folder - serve index.html inside
- url: /(.*)$
static_files: public/\1/index.html
upload: public/.*/index.html
Remember that all this depends on your directory.
Here is also app.yaml and structuring web services documentation that could help.
I'm trying to deploy my web app on Google App Engine.
My project follows this structure
The app.yaml has this content:
runtime: nodejs14
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: \1
upload: (.*)
But, when I execute gcloud app deploy --project=MY PROJECT, and open my site, it looks like this:
I assume there is an error in the app.yaml file, but I don't understand what. Any ideas?
Update your second URL handler to:
- url: /(.*\.(svg|png))$
static_files: www/images/\1
upload: www/images/.*\.(svg|png)$
Then reference your img src like this:
<img src="/test.png" alt="oops" width="104" height="142">
One thing to add, you can also use static_dir as your second URL handler instead. This way it's easier organize static files per directory. Change your app.yaml to:
runtime: nodejs14
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /static-img
static_dir: www/images
In that example, what happens is that images located at www/images are mapped on URLs beginning at /static-img. You can use that URL to reference your img src in your HTML. For example:
<img src="/static-img/test.png" alt="oops" width="104" height="142">
Learn more at: https://cloud.google.com/appengine/docs/standard/nodejs/config/appref#handlers_static_dir
I'm deploying a static site using AppEngine and after many attempts to get the order of handlers correct, my app.yaml file now removes file extensions from urls while also displaying all css, js, images and other static resources which it doesn't if you get the handler order wrong.
***However, for some reason, only some of my static pages work when browsing. The others return a 404.
File structure:
Root
app.yaml
www (directory)
index.html: WORKS
page2.html: WORKS
page3.html: WORKS
(all others).html DON'T WORK
css
js
images
etc
My app.yaml is as follows:
runtime: python27
api_version: 1
threadsafe: true
#With the following handler order, .html is removed from urls and all static resources load fine.
#However, some static pages throw a 404, even though they're in same directory as those that work.
handlers:
- url: /(.*)
static_files: www/\1
upload: www/(.*)
secure: always
- url: /
static_files: www/index.html
upload: www/index.html
secure: always
- url: /(.+)
mime_type: text/html
static_files: www/\1.html
upload: www/(.+)
secure: always
Is it possible to specify the equivalent of a default document for directories in Google App Engine so that navigating to that directory automatically redirects to its index.html for example, if it contains one?
If I have this in my app.yaml:
- url: /demos
static_dir: demos
and the demos directory contains an index.html page, how can I tell App Engine to automatically redirect to that page?
App Engine uses regular expression matches on the request path to determine what script to call or document to serve. If you just have the one index document, you can do it like this:
- url: /demos/
static_files: demos/index.html
upload: demos/index\.html
More generally, you can define static files for paths ending in slashes ('directories') like this:
- url: /(.*)/
static_files: \1/index.html
upload: .*/index\.html
I got this to work by using this in my yaml.
- url: /(.+)
static_files: static/\1
upload: static/(.+)
- url: /
static_files: static/index.html
upload: static/index.html
Replace static with demos and you should be set. It redirects the blank domain to index.html and al others to the static folder.
For GAE/J, add the following to your web.xml file.
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
www.example.com/test/ will now serve www.example.com/test/index.html
- url: /demos(/.+|)/
static_files: demos\1/index.html
upload: demos/(.+/|)index\.html
- url: /demos/
static_dir: demos
I am trying to develop on Google App Engine and in the list of the errors displayed in the admin console I always see the following:
/favicon.ico
i read the documentation , added a new folder called static and added this in my app.yaml:
- url: /favicon.ico
static_files: static/favicon.ico
upload: static/favicon.ico
but even now I'm getting the same error...
This entry should be placed before the entry for the main handler, like:
- url: /favicon.ico
static_files: media/img/favicon.ico
upload: media/img/favicon.ico
- url: /robots.txt
static_files: media/robots.txt
upload: media/robots.txt
- url: .*
script: main.py
The entries are processed in order of apperance and first one that matches wins.
If you are doing this in Java, I got rid of the error by putting a blank "favicon.ico" file in the "war" directory.
If you want to make your own quick and ugly "favicon.ico" file, this website was super easy to use: http://www.favicon.cc/
For your application, favicon.ico should be a static image. You can upload a favicon.ico file with your application, and in your app.yaml file configure your application to serve the image when the url /favicon.ico is requested. Below is an example entry in your app.yaml file for /favicon.ico. We assume you include the favicon.ico file in the directory path static/images:
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: static/images/favicon.ico
is written here
I am using this snippet in a GAE app configuration:
handlers:
- url: /(.*\.(ico|png|webmanifest))$
static_files: faviconfiles/\1
upload: faviconfiles/.*\.(ico|png|webmanifest)$
I then put the corresponding set of files (these days if you seriously want to set a "favicon" it's a set of files incl. e.g. apple-touch-icon.png) into the ./faviconfiles directory next to my app.yaml.