I have a project on my server and there are some confidential PDF and SWF extention files which is load from our website. But i don't want that any one those are not the access of our website can't be able to access these confidetial data by just copy and paste the link url on address bar. To avoid this security hook you need to just write a code in your htaccess file.
Below is the code of htaccess :-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourDomainName/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourDomainName.*$ [NC]
RewriteRule \.(swf|pdf)$ - [F,NC]
</IfModule>
Changes in code : You just need to copy the above code and put it into a file. After that change bold highlited text "yourDomainName" with your website domain name. Suppose your website name is 'www.yahoo.com' then here yahoo is your domain name so you have to replace yahoo with the 'yourDomainName' into the code. After that save this file with the name '.htaccess'. After creating this htacess file put it on the root of your website folder.
Testing your code : When you are testing the code don't forget to clear the catche of your browser every time.
Now try to access any pdf or swf file by direct link on browser. It will show a permission message of unauthorize access.
Like below screne shot-
Happy coding :)
Below is the code of htaccess :-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourDomainName/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourDomainName.*$ [NC]
RewriteRule \.(swf|pdf)$ - [F,NC]
</IfModule>
Changes in code : You just need to copy the above code and put it into a file. After that change bold highlited text "yourDomainName" with your website domain name. Suppose your website name is 'www.yahoo.com' then here yahoo is your domain name so you have to replace yahoo with the 'yourDomainName' into the code. After that save this file with the name '.htaccess'. After creating this htacess file put it on the root of your website folder.
Testing your code : When you are testing the code don't forget to clear the catche of your browser every time.
Now try to access any pdf or swf file by direct link on browser. It will show a permission message of unauthorize access.
Like below screne shot-
Happy coding :)
Tags:
htaccess