skip to Main Content

I want to deny access to the js, css files
If someone trying to access such file.js or file.css
the website redirect him to 404

but below code is not working. because it even block serving web pages.
i just need to block access from js css files being browsed by users

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+.)?mysite.com/ [NC]
RewriteRule .*.(js|css)$ - [F]

2

Answers


  1. I’ve implemented the following script on my website for the same purpose. Could you modify your .htaccess file like this:?

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://(.+.)?mysite.com/ [NC]
    RewriteRule .js$ /path/to/404-error-page [R,L]
    RewriteRule .css$ /path/to/404-error-page [R,L]
    

    .+.(js|css)$ that regex means match any files with the .js and .css extensions so it can also block valid requests for .js and .css files needed by your web pages.

    Login or Signup to reply.
  2. Try:

    <FilesMatch ".(js|css)$">
        Order Deny,Allow
        Deny from all
        Allow from enter_ip_from_allowed_client
        ErrorDocument 404 /404.html
    </FilesMatch>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search