S3 static website RedirectAllRequestsTo throws InvalidURI instead of redirecting some requests

0

I have a bucket configured to RedirectAllRequestsTo a different domain. No special routing rules or nuance, just redirect everything, always. But I find that some requests throw an error from this s3 bucket because they aren't parseable! I would expect it to redirect regardless, and let the other domain deal with that.

$ aws s3api get-bucket-website --bucket www.example.com
{
    "RedirectAllRequestsTo": {
        "HostName": "example.com",
        "Protocol": "https"
    }
}
$curl www.example.com.s3-website-us-west-2.amazonaws.com/%C0
<html>
<head><title>400 Bad Request</title></head>
<body>
<h1>400 Bad Request</h1>
<ul>
<li>Code: InvalidURI</li>
<li>Message: Couldn&#39;t parse the specified URI.</li>
...
$ curl -i www.example.com.s3-website-us-west-2.amazonaws.com/foo
HTTP/1.1 301 Moved Permanently
x-amz-id-2: 9UT/mRKgWwR2g3k5IXBWUSwntDDC9sQiJveFb7mNBLvWtSn32E9fnL+XKy/OiCrkkYGx7DoXBy8=
x-amz-request-id: 8TDJS9A5VB1AX0YV
Date: Thu, 17 Aug 2023 22:37:02 GMT
Location: https://example.com/foo
Server: AmazonS3
Content-Length: 0

Is there any way to actually redirect all requests?

gefragt vor 9 Monaten249 Aufrufe
1 Antwort
0

%C0 is the url encoding for À in the Windows-1252 encoding scheme. You should encode your url-query strings in utf8.

For À this would be %C3%80.

I setup my redirect as follows (same as yours just left out the protocol.

% aws s3api get-bucket-website --bucket static.swyd.ca --region eu-west-1
{
    "RedirectAllRequestsTo": {
        "HostName": "swyd.ca"
    }
}

When I test this with %C0 it fails:

% curl -vko /dev/null http://static.swyd.ca.s3-website-eu-west-1.amazonaws.com/%C0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 52.218.97.236:80...
* Connected to static.swyd.ca.s3-website-eu-west-1.amazonaws.com (52.218.97.236) port 80 (#0)
> GET /%C0 HTTP/1.1
> Host: static.swyd.ca.s3-website-eu-west-1.amazonaws.com
> User-Agent: curl/8.1.2
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< x-amz-request-id: D5RTSV1DKFXB8PRQ
< x-amz-id-2: DLiV+/FbrPj5myRI7HhUuBJb3M=
< Content-Type: text/html; charset=utf-8
< Date: Fri, 18 Aug 2023 08:11:20 GMT
< Server: AmazonS3
< Content-Length: 348
< Connection: close

Using UTF8 encoding it works:

% curl -vko /dev/null http://static.swyd.ca.s3-website-eu-west-1.amazonaws.com/%C3%80
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 52.218.37.188:80...
* Connected to static.swyd.ca.s3-website-eu-west-1.amazonaws.com (52.218.37.188) port 80 (#0)
> GET /%C3%80 HTTP/1.1
> Host: static.swyd.ca.s3-website-eu-west-1.amazonaws.com
> User-Agent: curl/8.1.2
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< x-amz-id-2: fzEpLLxY4XH+6/dfgzCCfEaQ9AaH++=
< x-amz-request-id: CDSCQ3ND8
< Date: Fri, 18 Aug 2023 08:14:00 GMT
< Location: http://swyd.ca/%C3%80
< Server: AmazonS3
< Content-Length: 0
AWS
EXPERTE
beantwortet vor 9 Monaten
  • Appreciate your response, but this is different from my question. I can't control the things people type into their URL bar, and I'm not trying to. I'm trying to understand why the bucket returns a 400 ever given that I've set it to always redirect.

  • Appreciate your response, but this is different from my question. I can't control the things people type into their URL bar, and I'm not trying to. I'm trying to understand why the bucket returns a 400 ever given that I've set it to always redirect.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen