Please I need help guys.
Is it possible to check if a file is requested by a page or if it is being viewed directly through it's URL?
Let's say we have a JavaScript file named file.js
and I have a page named page.html
and on the page, we linked to the JS file to use it for some functions.
This what I have tried:
RedirectMatch 301 ^/.*$ https://example.com
With the above code, the file.js
redirects to https://example.com
when it is viewed through its URL. This is one thing I actually want. But when the file is requested by the page.html
, it doesn't show up. It seems to have been redirected as well. I want it to be served when it is requested by the page.
How can I through the HTACCESS
check if file.js
is requested by page.html
to allow its usage but redirect it if it is requested directly with its URL?
ALSO: Maybe this can be done by checking the URL through which the file is being requested from wether it matches the file url or not. I don't know by the way...
I need your help.
Thank you!
Edit:::
I want to know if I can set it up so that even after it is seen through a page, it still cannot be viewed directly through its URL. And if what I'm requesting is possible by the way.