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 import Java Web Project in Eclipse
- Maven vs. Gradle: A Comparison with Examples
- Deploy jasper reports in JasperReports Server using Parameters
- Eclipse shortcuts for Open Call Hierarchy
- Eclipse/STS shortcut keys for Uppercase and Lowercase
- Server Tomcat Server at localhost failed to start in Eclipse
- WAMP/XAMPP Server- .htaccess redirect rule not working on localhost
- wamp- Could not execute menu item (internal error): The service has not been started
- Types of URL pattern supported by Tomcat
- How to show and hide File extension in Windows 7?