我可以使用.htacces或Javascript禁用直接网址访问吗?
假设我的网址为http://example.com/js/example.js
我需要在Android应用中访问Javascript文件,但我不需要允许任何人在浏览器中查看该文件是否有人拥有JS链接。
我可以这样做吗?
答案 0 :(得分:0)
您可以使用.htpassword
文件限制对其的访问。
在项目根目录的.htaccess
文件中:
<FilesMatch "js/example.js$">
AuthName "Application Only"
AuthType Basic
AuthUserFile /home/myProject/web/.myhtpasswd
require valid-user
</FilesMatch>
在项目根目录的.myhtpasswd
文件中(或您想要的任何地方):
test:$apr1$0ciO9Yg.$AUTSp18D2EWiZYN3u08HX/
您可以使用online tools创建此文件。
在Android应用程序中,您可以通过在HttpURLConnection
对象上指定授权来访问此文件。 See my other answer for more informations