Skip to content

Instantly share code, notes, and snippets.

@xenotropic
Created July 23, 2020 23:23
Show Gist options
  • Save xenotropic/9d4570cfa956553166c8665ba34a8e08 to your computer and use it in GitHub Desktop.
Save xenotropic/9d4570cfa956553166c8665ba34a8e08 to your computer and use it in GitHub Desktop.
Script to create htaccess file for simple auth, but also allow FB crawler in by IP address
# Creates an .htaccess file that sets up simple auth (use SSL only!) but allows FB IP address through
# FB indicates its IP addresses shift often, so will need to be cronned
# See https://developers.facebook.com/docs/sharing/webmasters/crawler
# MIT License https://opensource.org/licenses/MIT
# You need to create and update location of AuthUserFile, your php interpreter
#!/usr/bin/php
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/location/of/.htpasswd"
<RequireAny>
Require valid-user
<?php
$fb_ips=`whois -h whois.radb.net -- '-i origin AS32934' | grep ^route`;
$fb_ips = str_replace ("route6:", "require ip ", $fb_ips);
$fb_ips = str_replace ("route:", "require ip ", $fb_ips);
echo $fb_ips;
?>
</RequireAny>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment