How to block direct access of File using htaccess
In this htaccess tutorial, we are going to show how you can prevent the direct access of file/URL of your website. Sometimes website owner doesn’t want that user can access their zip, CSS, etc file directly.
To prevent the direct access, you need to add the below script in the .htaccess file.
.htaccess
RewriteEngine on
# script to stop direct link of zip and css file
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example[NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.*$ [NC]
RewriteRule \.(zip|css)$ http://www.example.com[R,L]You can add multiple file extensions by ORing the pipe(|) symbol.
(gif|zip|png|js|css|bmp)References
Similar Posts
- How to create user library in Eclipse IDE
- IntelliJ IDEA shortcuts for equals() and hashCode()
- The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
- How to change default Author and Committer in Eclipse Git plugin?
- IntelliJ IDEA– Remove/Optimize unused imports shortcut keys