Forum Moderators: phranque

Message Too Old, No Replies

Banning via Htaccess

Banning via Htaccess

         

swapshop

8:45 pm on Apr 18, 2008 (gmt 0)

10+ Year Member



I have a spammer hammering a forum we run.

I am trying to ban then from the site via htaccess

in htaccess we have

<Files *>
order deny,allow

deny from xx.xx.xx.xx

</Files>

I need to ban the link in their forum when click to coming to our site.

Any ideas

wilderness

12:35 am on Apr 19, 2008 (gmt 0)

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



SetEnvIf Referer
[httpd.apache.org...]

[google.com...]

swapshop

2:30 am on Apr 19, 2008 (gmt 0)

10+ Year Member



Sorry could you give me a example still very new to this

I have a IP I will to redirect to a new url

wilderness

2:36 am on Apr 19, 2008 (gmt 0)

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



Sorry could you give me a example still very new to this

And have Jim make a gelding out of me ;)

This is how I located the Webmaster World forum some eight years ago.

[google.com...]

Just go through the SERPS, until you find examples/tutitorials which inlcude SetEnvIf, however in all honesty?

The previous link I provided will get you there faster.

wilderness

2:40 am on Apr 19, 2008 (gmt 0)

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



Here's a very old and very incomplete explantion:

[webmasterworld.com...]

swapshop

2:54 am on Apr 19, 2008 (gmt 0)

10+ Year Member



SetEnvIf Referer ^www\.domain\.com\.$ banned
SetEnvIf Request_URI ^errror\.php$ allowed

<Files *>
order deny,allow

Site I am trying to ban is say www.domain.com

This isnt working

wilderness

3:14 am on Apr 19, 2008 (gmt 0)

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



I'm not sure on the URI line.
Although I seem to recall that 403 file links (which I've never used) are located in the upper portion of the lines.

<Files *>
order allow,deny
deny from xx.xx.xx.xx
SetEnvIfNoCase Referer ^www\.domain\.com banned
allow from all
deny from env=banned
</Files>

edited.

Please note; you have the referrer beginning with "www.".
In the event the referrer begins with "http://www."
Your line will have no effect.

jdMorgan

3:55 am on Apr 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




SetEnvIf Referer ^http://www\.domain\.com banned
SetEnvIf Request_URI ^path-to-custom-403-page\.html$ allowed
SetEnvIf Request_URI ^robots\.txt$ allowed
#
Order Deny,Allow
#
Deny from 12.34.56.78
Deny from 34.56.0.0/255.255.0.0
Deny from 56.78.12.0/24
Deny from 78.12
Deny from hackers.com
Deny from env=banned
#
Allow from env=allowed

The first four Deny lines show examples of denying a specific IP address, and three ways to deny IP address ranges, by "base address" and netmask, by "base address" and CIDR notation, and by IP address prefix.

The fifth Deny line denies based on remote hostname, and will only work on a server that has reverse-DNS lookups enabled (many don't).

The final two lines address your question. Deny line six denies your unwelcome referrer by use of the "banned" server variable set by the SetEnvIf directive above, and the final line allows *all* accesses to your custom 403 error page and your robots.txt file, overriding the previous "Denies" in order to save you a whole lot of trouble...

Jim

swapshop

4:04 am on Apr 19, 2008 (gmt 0)

10+ Year Member



Jim is this in the directive?

<Files *>
order deny,allow

swapshop

4:11 am on Apr 19, 2008 (gmt 0)

10+ Year Member



Tried

<Files *>
SetEnvIf Referer ^http://www\.domaintoban\.com banned
SetEnvIf Referer ^http://domaintoban\.com banned
SetEnvIf Request_URI ^error\.php$ allowed
SetEnvIf Request_URI ^robots\.txt$ allowed

order deny,allow

deny from www.domaintoban.com
deny from domaintoban.com

But this is allowing the link from there forum to our site to still work

Ie link is

[ourdomain.com...]

wilderness

1:36 pm on Apr 19, 2008 (gmt 0)

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



did you include?

Deny from env=banned

jdMorgan

2:54 pm on Apr 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please test the code exactly as I posted it, changing only the IP addresses/domain names. I cannot help debug a problem if you're going to modify the code arbitrarily; The <Files *> container was completely unnecessary, so I removed it.

Be sure to completely flush your browser cache between tests from different referrers; Otherwise your browser will cache the images and pages, and show them to you without making a request to your server. If no request is made to your server, then your server-side code can have no effect.

See the prior note about reverse-DNS not being available on many servers. These two lines won't work on many or most shared-hosting servers:


Deny from www.domaintoban.com
Deny from domaintoban.com

However, this is not very important, since those two lines would only stop the domaintoban server itself from accessing resources on your site.

You can also replace these two lines:


SetEnvIf Referer ^http://www\.domaintoban\.com banned
SetEnvIf Referer ^http://domaintoban\.com banned

with one:

SetEnvIf Referer ^http://(www\.)?domaintoban\.com banned

Note also that the HTTP Referer header is optional. If a client does not send a referrer, then access will be allowed (as it must be to prevent problems with corporate and ISP caching proxies such as those used by all AOL users).

For best portability between hosts and servers, observe the *exact* form of each directive, including spacing and capitalization.

Jim

Doood

2:56 pm on Apr 19, 2008 (gmt 0)

10+ Year Member



What I do sometimes is redirect all traffic from a certain domain to a different page on my site, maybe one with ads or something. But this may not be what you want.


RewriteCond %{HTTP_REFERER} theirdomain\.com/
RewriteRule ^$ http://www.yourdomain/adpage [R=301,L]

g1smd

7:46 pm on Apr 19, 2008 (gmt 0)

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



I sometimes do that as a rewrite so that every URL they request always shows the same page of content, with the URL in their browser staying the same.

swapshop

11:21 pm on Apr 19, 2008 (gmt 0)

10+ Year Member



Sorry still lost with the code

RewriteCond %{HTTP_REFERER} theirdomain\.com/
RewriteRule ^$ [yourdomain...] [R=301,L]

This is causing 404 on the site.

Lets say the site is www.example.co.uk that has the link to our site

Now I want to redirect any user who clicks on that page to another site ie www.redirect.co.uk

Issue is spammers are adding adverts to the site and there is a link on a forum is generator mass spammers on the site

swapshop

7:29 pm on Apr 20, 2008 (gmt 0)

10+ Year Member



Polite Bump^ any additional ideas please?

wilderness

8:07 pm on Apr 20, 2008 (gmt 0)

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



With all due respect, you've been provided with three different "working" solutions.

With each instance, you have presented a reason a reason and/or question which is obvious to the three folks providing that solutions, that you have not completed your homework, whilst implementing the solution.

1) you need to modify these to your own requirements.
2) Read up on more htaccess/Apache useage
3) retain another to make these adjustments for you.

In this implentation, there are four questions that need answering:

[webmasterworld.com...]

1) Have you turned on rewrite
2) Have you renamed "theirdomain" and "yourdommain" to the correct names?
3) Have you renamed "adpage" to the correct page with extension?
4) Have you reviewed your error logs?