Some search engines support dynamic rendering (e.g., Google), so SEO optimization is less critical for them. However, for search engines that do not support dynamic rendering, SEO optimization is still essential.
Due to the adoption of a front-end and back-end separation technology, search engines cannot directly retrieve page content. Therefore, SEO optimization is necessary to improve the search engine indexing effect. This document will introduce the principles and configuration guide for SEO implementation in this project.
The SEO optimization solution adopted by this project involves prerendering via GitHub Actions, uploading the prerendered pages to an S3 bucket, and using Cloudflare Workers to proxy requests for SEO optimization.
Prerendering is a simple crawler. Starting from the provided SEO_BASE_URL, it requests a page at a time, uploads the rendered HTML content to the S3 bucket for caching, and extracts all the links on the page. If the link starts with SEO_BASE_URL or contains the SEO_CONTAINS_KEY keyword, the crawler will request and prerender the link until no new links are found.
When deploying the backend, you need to configure the following environment variables in GitHub (plain text):
And the following environment variables (encrypted):
Due to the large number of these environment variables, covering a significant part of the complete environment variable list, it is recommended to add these environment variables directly in GitHub during deployment for v0.2.0
and later versions, rather than through the Cloudflare panel. This can reduce the time cost of configuration to some extent.
After configuring the environment variables, you can manually trigger a Workflow in GitHub Actions. If everything is correct, the deployment will be completed quickly.
In the Cloudflare Workers panel, open the details page of your domain, click Workers Routes
, and add a new route. The route should be:
For example:
Select the Worker you deployed, and click save.
Then, click the sidebar menu > Rules
> Transform Rules
> URL Rewrite
> Create Rule
. The rule name can be anything, and the custom filter expression is:
This filter expression is optimized only for Google's indexing. For other search engines, please find their respective crawler UAs and fill them in.
Set the rewrite path to Dynamic
, with the value:
Select Preserve query
.
Reference configuration screenshot:
Click deploy to complete the SEO configuration.