Seite 1 von 1

.htaccess bestimmte Länder ausschließen

Verfasst: 24.03.2016 22:09
von Manuel1805
Hallo zusammen,

kann mir jemand sagen wie ich bestimmte Länder, wie z.B. Russland, Ukraine, China vom Besuch meiner Website ausschließen kann? Z.B. Bearbeiten meiner .htaccess-Datei.

1. Wo liegt diese Datei (ich habe die mehrmals (d.h. in verschiedenen Verzeichnissen) gefunden.
2. Wo muss ich was anpassen?

Anbei meine .htaccess im /html-Verzeichnis
Über eine zeitnahe Rückmeldung würde ich mich sehr freuen, bzw. mein Mailserver. ;-) (habe da leider so ein Spammer...)

Code: Alles auswählen

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteBase /

RewriteRule ^(.*)-f([0-9]*)/(.*)-t([0-9]*)-s([0-9]*).html viewtopic.php?f=$2&t=$4&start=$5&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*)/(.*)-t([0-9]*).html viewtopic.php?f=$2&t=$4&%{QUERY_STRING} [L]
RewriteRule global/(.*)-t([0-9]*).html ./viewtopic.php?f=1&t=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*)/index-s([0-9]*).html viewforum.php?f=$2&start=$3&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*)/ viewforum.php?f=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*) viewforum.php?f=$2&%{QUERY_STRING} [L]
RewriteRule ^forum.html index.php?%{QUERY_STRING} [L]

#
# Uncomment the statement below if you want to make use of
# HTTP authentication and it does not already work.
# This could be required if you are for example using PHP via Apache CGI.
#
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

#
# The following 3 lines will rewrite URLs passed through the front controller
# to not require app.php in the actual URL. In other words, a controller is
# by default accessed at /app.php/my/controller, but can also be accessed at
# /my/controller
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php [QSA,L]

#
# If symbolic links are not already being followed,
# uncomment the line below.
# http://anothersysadmin.wordpress.com/2008/06/10/mod_rewrite-forbidden-403-with-apache-228/
#
#Options +FollowSymLinks
</IfModule>

# With Apache 2.4 the "Order, Deny" syntax has been deprecated and moved from
# module mod_authz_host to a new module called mod_access_compat (which may be
# disabled) and a new "Require" syntax has been introduced to mod_authz_host.
# We could just conditionally provide both versions, but unfortunately Apache
# does not explicitly tell us its version if the module mod_version is not
# available. In this case, we check for the availability of module
# mod_authz_core (which should be on 2.4 or higher only) as a best guess.
<IfModule mod_version.c>
	<IfVersion < 2.4>
		<Files "config.php">
			Order Allow,Deny
			Deny from All
		</Files>
		<Files "common.php">
			Order Allow,Deny
			Deny from All
		</Files>
	</IfVersion>
	<IfVersion >= 2.4>
		<Files "config.php">
			Require all denied
		</Files>
		<Files "common.php">
			Require all denied
		</Files>
	</IfVersion>
</IfModule>
<IfModule !mod_version.c>
	<IfModule !mod_authz_core.c>
		<Files "config.php">
			Order Allow,Deny
			Deny from All
		</Files>
		<Files "common.php">
			Order Allow,Deny
			Deny from All
		</Files>
	</IfModule>
	<IfModule mod_authz_core.c>
		<Files "config.php">
			Require all denied
		</Files>
		<Files "common.php">
			Require all denied
		</Files>
	</IfModule>
</IfModule>

Re: .htaccess bestimmte Länder ausschließen

Verfasst: 26.03.2016 12:33
von hackepeter13
Schau mal, hier ist eine Beschreibung dazu: https://wiki.selfhtml.org/wiki/Webserve ... ie%C3%9Fen

Statt Deny from .aol.com könnstest du dann z.B. auch Deny from .ru für Russische Domains nehmen.
Hier hast du eine Top-Level-Domain Liste

Das fügst du einfach in deine gezeigt .htaccess (im Hauptverzeichnis, bspw. html-Verzeichnis) am Ende ein.

PS: alle anderen .htaccess Dateien die in irgendwelchen anderen Ordnern liegen, gelten nur für die jeweilige Ordner + Unterordner.
Die im Hauptverzeichnis (html-Verzeichnis) ist für die komplette Domain zuständig.

Re: .htaccess bestimmte Länder ausschließen

Verfasst: 27.03.2016 23:20
von Manuel1805
Hallo hackepeter13,

vielen Dank für Deine tolle Erklärung. Ich habe meine .htaccess-Datei im /html-Verzeichnis wie folgt angepasst:

Code: Alles auswählen

][/<IfModule mod_rewrite.c>
RewriteEngine on

RewriteBase /

RewriteRule ^(.*)-f([0-9]*)/(.*)-t([0-9]*)-s([0-9]*).html viewtopic.php?f=$2&t=$4&start=$5&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*)/(.*)-t([0-9]*).html viewtopic.php?f=$2&t=$4&%{QUERY_STRING} [L]
RewriteRule global/(.*)-t([0-9]*).html ./viewtopic.php?f=1&t=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*)/index-s([0-9]*).html viewforum.php?f=$2&start=$3&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*)/ viewforum.php?f=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*) viewforum.php?f=$2&%{QUERY_STRING} [L]
RewriteRule ^forum.html index.php?%{QUERY_STRING} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php [QSA,L]

</IfModule>

<IfModule mod_version.c>
	<IfVersion < 2.4>
		<Files "config.php">

			order deny,allow
        deny from .ua
        deny from .ru

		</Files>
		<Files "common.php">

			order deny,allow
        deny from .ua
        deny from .ru

		</Files>
	</IfVersion>
	<IfVersion >= 2.4>
		<Files "config.php">
			Require all denied
		</Files>
		<Files "common.php">
			Require all denied
		</Files>
	</IfVersion>
</IfModule>
<IfModule !mod_version.c>
	<IfModule !mod_authz_core.c>
		<Files "config.php">

order deny,allow
        deny from .ua
        deny from .ru

		</Files>
		<Files "common.php">

order deny,allow
        deny from .ua
        deny from .ru
		</Files>
	</IfModule>
	<IfModule mod_authz_core.c>
		<Files "config.php">
			Require all denied
		</Files>
		<Files "common.php">
			Require all denied
		</Files>
	</IfModule>
Deny from .ru
Deny froum .ua
</IfModule>

Deny from .ru 
Deny from .ua

Für mich ist noch nicht ganz klar, was am Ende heißt? Vor oder nach dem TAG </IfModule>?
Ich habe einfach mal beides probiert. Leider führt die Ergänzung nicht zum Erfolg. :cry:
...habe über einen Proxy in der Ukraine meine Website aufrufen können. Hast Du eine Idee?
Gruß
Manuel

Re: .htaccess bestimmte Länder ausschließen

Verfasst: 28.03.2016 12:32
von hackepeter13
Manuel1805 hat geschrieben: Für mich ist noch nicht ganz klar, was am Ende heißt? Vor oder nach dem TAG </IfModule>?
Am Ende heißt schlicht und einfach am Ende, also nach dem letzten Befehl eine neue Zeile und

Code: Alles auswählen

Order deny,allow
Deny from .ua
Deny from .ru
einfügen, speichern, hochladen, fertig.


PS: Das ][/ ganz am Anfang ist aber nicht original.

Re: .htaccess bestimmte Länder ausschließen

Verfasst: 30.03.2016 08:21
von Scanialady
und das funktioniert so mit den Länderkürzeln? Ich weiß, da gibts ne Möglichkeit Ländersperren über die Abkürzungen zu machen, da müssen aber gewisse Servervoraussetzungen bestehen. Funzt bei mir nicht.

Also ich muss da IP Ranges angeben. Fertige Blocklisten für China und Ostblock findet man z.B. hier. http://www.wizcrafts.net/htaccess-blocklists.html - oder einfach mal IP blocklist googlen