CORS for subdomain

I am beginner to websites and I need your help.

I recently made a site (example.com) and subdomain (sub.example.com).
I have separate htdocs for both sites. I wanted to keep all downloadable files (images, published pdfs) in example.com/files .

If I have all files there then
a href=“https://example.com/files/file.pdf” download=“file.pdf”>Link</a
is just opening file.pdf in new tab instead of downloading.

However if i make sub.example.com/files and set link:
a href=“files/file.pdf” download=“file.pdf”>Link</a
then it will download the file.

I know this have something to do with CORS(Cross-Origin Resource Sharing) but I can not find something resolving my issue. Is this possible to do?

Put your downloadable files in a file sharing host and link them back?

This host hosts websites only, and hosting files here and making them available to download isn’t allowed. You should host your downloadable files on file sharing hosts or sites :slight_smile:

2 Likes

What If I actually do not use InfinityFree for hosting? :grinning:

Well, you must create an .htaccess file to do that. But as BayoDino said, you cannot use it to host files.

Nothing.
Not using a hosting provider is better than using it but breaking its rules.

I do suspect CORS is the issue too. Specifically, I think you’re running into this security system:

https://infinityfree.net/support/javascript-error-using-api-or-mobile-android-app/

4 Likes

Well, if there is not anything I could do, I guess I will follow BayoDino’s advice.

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