-2

There is any way to block the direct access to a file? The file should be used on my website but i want to block it if someone access it directly, for example if you open this link: https://example.com/style.css you see an error message, but if you open the site, all the style sheet should be shown.

An example of this is the pro fontawesome css https://pro.fontawesome.com/releases/v5.8.1/css/all.css

You can't open this directly, but if you add this to your site and your domain is listed you can use the fonts.

Do you know any way to do this?

Lafa
  • 513
  • 2
  • 20
  • Something similar here: https://stackoverflow.com/questions/2679524/block-direct-access-to-a-file-over-http-but-allow-php-script-access. That thread assumes you're running Apache. – mattias Apr 17 '19 at 21:10
  • 3
    no, because a browser needs to access them, so can any user –  Apr 17 '19 at 21:10
  • @tim yes, but fontawesome did that, and i use that link for my website and i can use pro icons – Lafa Apr 17 '19 at 21:12
  • @mattias but with that i can't use the files on the website – Lafa Apr 17 '19 at 21:12

1 Answers1

1

It sounds like you want to set CORS policy: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Gerard
  • 768
  • 5
  • 20