如何防止網站之圖片與檔案被盜連呢?請修改以下檔案。
步驟一:進入apache設定檔。 #vim /etc/httpd/conf/httpd.conf 步驟二:找到底下這段設定,注意紅字部份。 <Directory "/var/www/html">
Options FollowSymLinks
# AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Order allow,deny Allow from all
</Directory> 改好後請存檔。
步驟三:到網站根目錄。 vim /var/www/html/.htaccess 步驟四:開始編寫程式。 RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://your--ip/.*$ [NC]<---只允許哪一個網域使用以下檔案格式 ,請根據自己之狀況設定。 RewriteCond %{HTTP_REFERER} !^http://your--ip/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://your--ip/.*$ [NC] RewriteRule \.(jpg|png|jpeg|gif|bmp|rar|zip|exe)$ - [F]<---哪些檔案格式受此限制,請自行增減。
|
|