Block certain file types with .htaccess?
Hello,
How is it possible to make specific file types inaccessible for direct access using htaccess? I embed some txt files via iframe and include them via PHP. Even when I use "deny from all, allow from 127.0.0.1," the iframe still displays "access denied." What can I do?
Hi,
with the .htaccess you can prohibit access to certain file types, but you can no longer include them via Iframe. PHP, on the other hand, can still access the .txt.
That’s what you do.
😉
If I understand this correctly, the txt’s can be integrated via Iframe, but can not be opened directly in the browser as a tab.
If I understood it correctly, I can only tell you that it won’t really go. Whether a file/side is opened as a browser tab or only integrated via Iframe makes no difference for the server. I’m not sure if Iframe vllt. yet special headers are sent to which you could check in the htaccess, but you could also ask them if available with manual queries.
If you want to prevent the complete access to txt’s, of course that would go.
So there are always 2 files written, so I could get the 1. Encrypt the file and use the 2nd for the Iframe, that would be a php that I can connect to the login session via a header. However, if the direct access is prohibited to the TXT, can I still use a php nen download? Then came also denied access when I click on Download.
I don’t understand anything from this part. If this is relevant to the problem, it would be nice if you could add a little context there.
This can be done very easily that the txt is available by request. PHP allows you to insert a data url instead of the url. This looks like this:
The same goes with binary data like Pdf’s and everything else with nem extra step.
You may need to add the download attribute to the browser the file name and above all that it is a txt.
I made it with:
Order Allow,Deny
Deny from All