AWS Amplify Rewrite not working for https non-www to www

Viewed 1296

I want to redirect from non-www to www and HTTP to HTTPS. I resolved HTTP to HTTPS by just doing permanent forwarding 301 in GoDaddy, but I can't redirect https://example.com to https://www.example.com

I tried the following (also tried the Rewrite 200): enter image description here

which results in: enter image description here

Any thoughts on why the redirect or rewrite is not working?

2 Answers

You can try with 302 code instead of using 301.

The Amazon forum on Github has a possible solution:

Try adding the following to the rewrites and redirection rules (using your own domain).

[
    {
        "source": "https://example.com",
        "target": "https://www.example.com",
        "status": "302",
        "condition": null
    },
    {
        "source": "/<*>",
        "target": "/index.html",
        "status": "404-200",
        "condition": null
    },
    {
        "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>",
        "target": "/index.html",
        "status": "200",
        "condition": null
    }
]
Related