.htaccess Whitelist for shared hosting

danielpmc

New member
1. Read through the example and adjust as necessary.
2. Google any codes to get indepth info
3. These go in your cPanel/public_html/.htaccess or equivalent, if file does not exist create a file name it .htaccess (.htaccess starts with a dot) and set the permissions (chmod) to 644


Code:
RewriteEngine on

Options -Indexes

IndexIgnore *

IndexIgnore */*

DirectoryIndex index.php index.html index.shtml

#Renews every 30 days Uncomment below AFTER SSL (including Lets Encrypt) is installed
#Header always set Strict-Transport-Security: max-age=2592000

Header always set X-Xss-Protection "1; mode=block"

Header always set X-Content-Type-Options "nosniff"

Header always set X-Frame-Options "DENY"
#Header always set X-Frame-Options "SAMEORIGIN"

#Uncomment below if SSL is installed on domain (forces http tp https)
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*)$ https://addyourdomainnamehere.com/$1 [R,L]

#Blocks uncommon requests. Error/access logs will show if anything legitimate is blocked. Remove word(s) as needed to unblock. 
RewriteCond %{REQUEST_METHOD} ^(CONNECT|DELETE|FLURP|HEAD|LABEL|LOCK|MOVE|OPTIONS|PRI|PROPFIND|PROPPATCH|PUT|TRACE)
RewriteRule .* - [F]

#Whitelist This only allows below to visit your site/server. You can add/remove/uncomment as many as you need.
Order Deny,Allow
Deny from all

#Browsers
SetEnvIfNoCase User-Agent .*ozilla/5.* good_bot
SetEnvIfNoCase User-Agent .*afar.* good_bot
SetEnvIfNoCase User-Agent edge good_bot
SetEnvIfNoCase User-Agent edge.* good_bot
SetEnvIfNoCase User-Agent .*edge.* good_bot
SetEnvIfNoCase User-Agent .*hrom.* good_bot
SetEnvIfNoCase User-Agent mac good_bot
SetEnvIfNoCase User-Agent mac.* good_bot
SetEnvIfNoCase User-Agent .*mac.* good_bot
SetEnvIfNoCase User-Agent msie good_bot
SetEnvIfNoCase User-Agent msie.* good_bot
SetEnvIfNoCase User-Agent .*msie.* good_bot
SetEnvIfNoCase User-Agent linu.* good_bot
SetEnvIfNoCase User-Agent .*linu.* good_bot
SetEnvIfNoCase User-Agent ipa.* good_bot
SetEnvIfNoCase User-Agent .*ipa.* good_bot
SetEnvIfNoCase User-Agent iphon.* good_bot
SetEnvIfNoCase User-Agent .*iphon.* good_bot
SetEnvIfNoCase User-Agent .*irefo.* good_bot
SetEnvIfNoCase User-Agent .*riden.* good_bot
SetEnvIfNoCase User-Agent ubunt.* good_bot
SetEnvIfNoCase User-Agent .*ubunt.* good_bot

SetEnvIfNoCase User-Agent .*aceboo.* good_bot
SetEnvIfNoCase User-Agent .*aho.* good_bot
SetEnvIfNoCase User-Agent api good_bot
SetEnvIfNoCase User-Agent api.* good_bot
SetEnvIfNoCase User-Agent .*api.* good_bot
SetEnvIfNoCase User-Agent bing good_bot
SetEnvIfNoCase User-Agent bing.* good_bot
SetEnvIfNoCase User-Agent .*bing.* good_bot
SetEnvIfNoCase User-Agent .*oogle.* good_bot
SetEnvIfNoCase User-Agent .*roi.* good_bot
SetEnvIfNoCase User-Agent slur.* good_bot
SetEnvIfNoCase User-Agent .*slur.* good_bot

#Uncomment below if E-Commerce, etc... is being blocked
#SetEnvIfNoCase User-Agent curl good_bot
#SetEnvIfNoCase User-Agent cur.* good_bot
#SetEnvIfNoCase User-Agent .*cur.* good_bot

#Uncomment below add IP if needed. (E-Commerce, Monitoring, DB, Remote, RSS, etc...)
#Allow from 123.123.1233.123
#Allow from 123.123.1233.123
#Allow from 123.123.1233.123

Allow from env=good_bot

#Below will show if somebody gets an error. Be decent with your words. Use google for error info.
#ErrorDocument 400 "Your-Words-Here"
#ErrorDocument 401 "Your-Words-Here"
#ErrorDocument 403 "Your-Words-Here"
#ErrorDocument 404 "Your-Words-Here"
#ErrorDocument 500 "Your-Words-Here"
#ErrorDocument 502 "Your-Words-Here"

Be safe out there!
 
Last edited:
Top