How can I translate my .htaccess to AWS Amplify's rewrites

Viewed 357

I'm serving an Angular SPA on AWS Amplify, and I would like to recreate the same rewrite rules as I have in my .htaccess file:

RewriteEngine On

# Remove trailing /
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Rewrite spiders to static html
RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|msnbot|yahoo|Baidu|aolbuild|facebookexternalhit|iaskspider|DuckDuckBot|Applebot|Almaden|iarchive|archive.org_bot) [NC]
RewriteCond %{DOCUMENT_ROOT}/static%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ /static/$1.html [L]

# Rewrite spiders to static index.html
RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|msnbot|yahoo|Baidu|aolbuild|facebookexternalhit|iaskspider|DuckDuckBot|Applebot|Almaden|iarchive|archive.org_bot) [NC]
RewriteCond %{REQUEST_URI} "^/$"
RewriteRule ^ /static/index.html [L]

# If an existing asset or directory is requested, serve it
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# If the requested resource doesn't exist, use the Angular app entry point
RewriteRule ^ /index.html

It seems AWS Amplify doesn't support an appended .htaccess file (?), but allows you to configure rewrites and redirects in the console. It asks for this format:

[
    {
        "condition": "",
        "source": "",
        "status": "200",
        "target": ""
    }
]

If i try to set "condition" to "%{HTTP_USER_AGENT} (googlebot|bingbot|msnbot|yahoo|Baidu|aolbuild|facebookexternalhit|iaskspider|DuckDuckBot|Applebot|Almaden|iarchive|archive.org_bot) [NC]" and save, the value is set to null.

Any ideas on how to format this?

0 Answers
Related