Search code examples
.htaccessmod-rewrite

Prevent hotlinking a 1 specific URL but allow on all others


I know the htaccess method for preventing hotlinking on every site aside of your own domain but i need something more advanced if possible

I would like to allow access on my personal server and all other sites , but yet pinpoint out a few select sites and ban them from hotlinking

pretty much i want to ALLOW ALL and deny a specific IP or URL

Allow : mywebdomain.com allothersites.com

Prevent : donotallowthissite.com donotallowthissite2.com

is this possible , if so can you share how to achieve it ty ?

I am currently using this to allow access to hotlink all my files to a 3rd party server with multiple servers , but its too confusing to keep adding new servers and direct ids to each site , so i want to allow ALL to hotlink from my server, but when i find someone copyrighting my material i want to block that site and id specifically

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?nitrografixx.com [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?www(2|32|26|3|29|7|5).myfantasyleague.com.+(15982|21316|51396|47164|64314|43757|43757|63884|72807|54905)$ [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?www(2|32|26|3|29|7|5).myfantasyleague.com.+(15982|21316|51396|47164|64314|43757|43757|63884|72807|54905).+$ [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?football(2|32|26|3|29|7|5).myfantasyleague.com.+(15982|21316|51396|47164|64314|43757|43757|63884|72807|54905)$ [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?football(2|32|26|3|29|7|5).myfantasyleague.com.+(15982|21316|51396|47164|64314|43757|43757|63884|72807|54905).+$ [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?football.+.myfantasyleague.com.+(mb|site_news|choose_schedule) [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?football.+.myfantasyleague.com.+(h2h|seed_playoff_teams|playoff_schedule_setup|general_playoff_setup|transaction_setup|randomize_schedule|set_draft_order|change_draft_pick|adjust|delete_adjustments|new_predraft|calculate|waivers|rearrange_schedule|accounting|delete_transactions|trades|history|save_award|delete_accounting|submit_lineups|franchise_setup|options|message|custom_waiver_order|commish_email_setup|invite_franchise_owners|league_calendar_setup|fee_setup|standings_setup|division_conference_setup|select_packaged_waiver_rules)$ [NC]

RewriteRule \.(jpg|jpeg|png|gif|js|css)$ - [NC,F,L]

Solution

  • Try:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} ^https?://(www\.)?donotallowthissite\.com [NC,OR]
    RewriteCond %{HTTP_REFERER} ^https?://(www\.)?donotallowthissite2\.com [NC,OR]
    RewriteCond %{HTTP_REFERER} ^$
    RewriteRule \.(jpg|jpeg|png|gif|js|css)$ - [NC,F,L]
    

    Using the sites you want to block and using the [OR] flag.

    So any other sites other than the two listed in the conditions will not hit the rule.