Forum Moderators: open

Message Too Old, No Replies

A Simple Beginning

with htaccess

         

wilderness

8:15 pm on Jul 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My own htaccess is just under 800 lines. A short while back it was nearer 1500. I was able to spend some time converting ranges of which I initally (when beginning with htaccess) used deny lines for multiple ranges into regular expressions.
The following example is ONLY meant to provide a beginning for those not yet using htaccess or for other beginners yet to implement some other htaccess options.

The lines below are only suggestions and may NOT be beneficial to every webmaster.

SetEnvIf User-Agent ^Java keep_out
SetEnvIf User-Agent ^Web keep_out
SetEnvIf User-Agent Library$ keep_out
order allow,deny
deny from 63.148.99.
deny from 65.118.41.
allow from all
deny from env=keep_out
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://yourOtherdomain.net/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.yourOtherdomain.net/.*$ [NC]
RewriteRule .*\.[Jj][Pp][Gg]$¦.*\.[Gg][Ii][Ff]¦.*\.[Pp][Dd][Ff]$ - [F]
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteRule ^.*$ - [F]
RewriteCond %{HTTP_REFERER} ^www.addresses.com.* [OR]
RewriteCond %{HTTP_REFERER} ^www.datashaping.com* [OR]
RewriteCond %{HTTP_REFERER} ^http://www.weblinkvalidator.com/*
RewriteRule ^.*$ - [F]
RewriteCond %{HTTP_USER_AGENT} ^Microsoft
RewriteCond %{REMOTE_ADDR}!^131\.107\.
RewriteRule .* - [F]
RewriteCond %{REMOTE_ADDR} ^81\.86\.(12[8-9]¦1[3-9][0-9])\. [OR]
RewriteCond %{REMOTE_ADDR} ^81\.1(2[89]¦[3-5][0-9])\.
RewriteRule ^.*$ - [F]
Redirect Gone /yourDEletedPage.html
Redirect Permanent /yourOldPage.html [yourdomain.com...]

SetEnvIf User-Agent ^Java keep_out
SetEnvIf User-Agent ^Web keep_out

deny UA's that BEGIN with either "Java or Web" and end with anything or any amount of chracters

SetEnvIf User-Agent Library$ keep_out

UA that ENDS with "Library" and is preceded by anything and any amount of characters

deny from 63.148.99.
deny from 65.118.41.

These two lines deny entry to Cyveillance and even though they exceed Cyveillance's ranges, the extended portion merely effects the backbone provider Qwest. (my own choice)

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://yourOtherdomain.net/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.yourOtherdomain.net/.*$ [NC]
RewriteRule .*\.[Jj][Pp][Gg]$¦.*\.[Gg][Ii][Ff]¦.*\.[Pp][Dd][Ff]$ - [F]

Prevents deep-linking to your images. There are a variety of methods to accomplish this. Jim uses one which allows the language translate pages and others to link to images. There are also some syntax corrections which can be made to eliminate the duplication of lines I have.

RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteRule ^.*$ - [F]

Denies both blank UA and UA that contains "-".
This is not for every webmaster and is my own choice.

RewriteCond %{HTTP_REFERER} ^www.addresses.com.* [OR]
RewriteCond %{HTTP_REFERER} ^www.datashaping.com* [OR]
RewriteCond %{HTTP_REFERER} ^http://www.weblinkvalidator.com/*
RewriteRule ^.*$ - [F]

These are coming referring pages or sites that many webmasters do not desire.

RewriteCond %{HTTP_USER_AGENT} ^Microsoft
RewriteCond %{REMOTE_ADDR}!^131\.107\.
RewriteRule .* - [F]

Denies ALL UA's which begin with Microsoft and DO NOT come from the ranges 131.107.255.255

Redirect Gone /yourDEletedPage.html

A note to desireable robots that a page has been removed from your site.

Redirect Permanent /yourOldPage.html [yourdomain.com...]

A note to desireable robots that a page has been moved to another location. May also be a domain outside your own.

RewriteCond %{REMOTE_ADDR} ^81\.86\.(12[8-9]¦1[3-9][0-9])\. [OR]
RewriteCond %{REMOTE_ADDR} ^81\.1(2[89]¦[3-5][0-9])\.
RewriteRule ^.*$ - [F]

Denies specific range with mod_Rewrite conditons. I've only used these two lines as an example because the close that portion of my file. The ranges are only significant to me and should ONLY be used if they are not beneficial to your websites.

If there are any questions?
I'll do my best to assist.
There are others which are more adapt at this than myslef. Hopefully they will jump in should I provide inaccurate information.

Don

wilderness

8:39 pm on Jul 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One of our participants has taken the opportunity to show me what they believe to be a flaw?

81.135.48.65 - - [15/Jul/2003:13:30:04 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"
81.135.48.65 - - [15/Jul/2003:13:30:19 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"
81.135.48.65 - - [15/Jul/2003:13:30:20 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"
81.135.48.65 - - [15/Jul/2003:13:30:22 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"
81.135.48.65 - - [15/Jul/2003:13:30:25 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"
81.135.48.65 - - [15/Jul/2003:13:30:26 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"
81.135.48.65 - - [15/Jul/2003:13:30:32 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"
81.135.48.65 - - [15/Jul/2003:13:30:32 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"
81.135.48.65 - - [15/Jul/2003:13:30:41 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"
81.135.48.65 - - [15/Jul/2003:13:30:42 -0700] "GET /mypage.html HTTP/1.1" 403 - "http://google.btopenworld.com/dynamic/search/google_search_panel.jsp" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTT V3.0)"

It is irrelavant to me that a party used google to get to my site in this instance.
Only that I do NOT desire any traffic from BT or even most of the UK and RIPE for that matter.

wilderness

11:58 pm on Jul 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To add that we have some undesireable bot folks monitoring this forum?

208.185.93.9 - - [15/Jul/2003:15:28:01 -0700] "GET / HTTP/1.0" 403 - "-" "-"

Abovenet Communications, Inc ABOVENET-6 (NET-208-184-0-0-1)
208.184.0.0 - 208.185.255.255
ADDR.COM MFN-B652-208-185-93-0-24 (NET-208-185-93-0-1)
208.185.93.0 - 208.185.93.255

This person saw that their referring pages are denied in my example and attempts entry and is denied under the blank UA.
No matter their IP range is denied also.
In fact the entire Abovent range is denied.