1

Can I disable direct url access using .htacces or Javascript..?

Assume my URL is http://example.com/js/example.js

I need to access Javascript file in Android app but I do not need to allow anyone to view that file in a browser whether anyone have the JS link.

Can I do this..?

1 Answer 1

0

You can restrict access to it using a .htpassword file.

In your .htaccess file at the root of your project:

<FilesMatch "js/example.js$">
    AuthName "Application Only"
    AuthType Basic
    AuthUserFile /home/myProject/web/.myhtpasswd
    require valid-user
</FilesMatch>

In your .myhtpasswd file at the root of your project (or wherever you want):

test:$apr1$0ciO9Yg.$AUTSp18D2EWiZYN3u08HX/

You can use online tools to create this file.

In your Android application you will be able to access this file by specifying the Authorization on your HttpURLConnection object. See my other answer for more informations.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried the way but still I can access my file in the browser URL. I only changed AuthUserFile path to my path and created .htpasswd file in the way you showed me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.