简体   繁体   中英

Allow access to the specific IP addresses which starts with specific series using .htaccess

I have my own shared server where my sites are hosted. Planning to consolidate/maintain all commonly used files like images, css, js etc., as different sub-domain. For that domain, i want to deny the other users to access those files (preventing hotlinking). All my website IP addresses are starting with 208. . . ** series. How to achieve the result?

Here are my basic htaccess lines,

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|js|css)$ - [F]

Kindly share your ideas. TIA

You can add another condition:

RewriteEngine on
# Options +FollowSymlinks

RewriteCond %{REMOTE_ADDR} !^208\.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|js|css)$ - [F]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM