Skip to content

Is this the correct way to redirect all route traffic based on useragent? #1698

@crooksey

Description

@crooksey

Due to the fact my SPA application has hydration issues on ios (separate bug) I am currently in a position where I cannot use SSR, so I have to use an SPA and pre-rendered pages for SEO.

My application currently sits on azure static sites and I am very happy with the performance and devops integrations.

So i am looking at integrating a service where search engine bots are re-directed to a static copy of my site, this would be easy in IIS or Nginx, but ideally I would like to stay on static-web-app.

The service page-replica publishes these instructions:

  1. Detect bot traffic using the User-Agent header (e.g., Googlebot, Bingbot, Facebook, Twitter, etc.).
  2. Redirect bots to the prerendered cache URL (e.g., https://cache.page-replica.com/[siteId]/[domain]/[path]).
  3. Serve normal users your regular dynamic site as usual.

I think I can do this via staticwebapp.config.json, but I am unsure.

Will the below wildcard routing and re-direct work?

{
    "routes" : [
        {
            "route": "/*",
            "redirect": "https://cache.page-replica.com/200/www.example.com/*",
            "headers": {
                "User-Agent": "Googlebot"
                }
        },
        {
            "route": "/*",
            "redirect": "https://cache.page-replica.com/200/www.example.com/*",
            "headers": {
                "User-Agent": "bingbot"
                }
        }

    ],
    "navigationFallback": {
        "rewrite": "/index.html",
        "exclude": ["/images/*.{png,jpg,gif}", "/css/*"]
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions