How to add `.well-known` directory to site without a 308 redirect?

I need to add a /.well-known directory to my site with a JSON file in it, for an external service to verify that I own the domain.

I have tried adding a public/.well-known directory to my source repository, which does make the necessary file appear at the right location. However, this seems to be behind a 308 redirect, and the external service does not accept this as a valid HTTP response code. For example:

curl -X HEAD -i 'https://[redacted].com/.well-known/microsoft-identity-association.json' 
[...]
HTTP/2 308 
cache-control: public, max-age=0, must-revalidate
content-type: text/plain
date: Tue, 14 Jan 2025 18:57:40 GMT
location: https://www.[redacted].com/.well-known/microsoft-identity-association.json
refresh: 0;url=https://www.[redacted].com/.well-known/microsoft-identity-association.json
server: Vercel
strict-transport-security: max-age=63072000

And Microsoft’s domain verification returns the following error message: “Verification of publisher domain failed. Request returned the wrong HTTP status code. Expected: OK, Actual: 308.”

I tried searching the Vercel docs and got a recommendation to add the following to my vercel.json file, but this did not make any difference:

    "routes": [
        {
            "src": "/.well-known/(.*)",
            "dest": "public/.well-known/$1"
        }
    ]

How can I make a file appear in a /.well-known directory without any 308 redirect?

I figured out my problem. I was trying to verify my https://[redacted].com domain, but that has a redirect to https://www.[redacted].com, which is where the 308 redirect was coming in. If I tried doing the curl -X HEAD -i command on the www.[redacted].com domain that it returns a 200.

2 Likes

I’m glad you got it working! Thank you for coming back to share how you did it. :smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.