简体   繁体   中英

.htaccess deny all except allow javascript access as well

I currently am blocking all access to one directory in on my server using .htacces

deny from all

I use php for all my coding, except at one point I use javascript to play mp3s from my secured directory. But this is blocked by the .htaccess

Is there anyway to allow the javascript access to the directory but still block people from typing in the url and gaining access to the files.

Sorry, I'm new to .htaccess and can't figure it out.

Thanks.

No, JavaScript is client side; thus, if it can access the files, the client can too.

Considering moving the files into a non-public directory, perhaps even outside of webroot, and then reading them & sending them to the client using a script. This can be easily accomplished with PHP.

Nope, not that I'm aware of. Why don't you just move the music into another directory that has an index so all the music files aren't listed?

I ended up using this code to allow access to mp3s and oggs and nothing else. It's not optimal but it works.

deny from all

<FilesMatch ".(ogg|mp3)$">
Order Allow,Deny
allow from all
</FilesMatch>

Thanks for the answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM