Skip to content Skip to sidebar Skip to footer

Deny Direct Access To Javascript Files In Iis Web Server

I have a web application which is in php and java script. if someone tries to enter the path of the java script file in the browser, the complete java script is being displayed in

Solution 1:

You cannot block direct access to the file. If you restrict access to the file, as you mentioned the php file will 'break' for users who don't have access to that js file.

You could however redirect users who visit the URL to the file directly: Javascript example:

<script>if(window.location.href.endsWith('baseView.js'))
{
    window.location = 'www.google.com'
}
</script>

You may also be able to use the .htaccess file to do this, which would be much better. (although I cannot test this myself right now, I'm not sure if it would work and not be invoked through the php file)

Note: This will in no way stop users from reading the Javascript file, so I am not sure why you want to do this.

Post a Comment for "Deny Direct Access To Javascript Files In Iis Web Server"