D
D
Dmitry2012-10-22 09:31:25
htaccess
Dmitry, 2012-10-22 09:31:25

How to redirect all but a few IPs in .htaccess?

The Internet is full of the opposite - redirect everyone, redirect to known IPs, etc.
And I need the following:
-if IP (or subnet, not important) is X or Y, then give index.php
-give index.html to everyone else or redirect to the directory / sorry/ (whichever is easier to implement).

Answer the question

In order to leave comments, you need to log in

7 answer(s)
I
Ivan Ilyasov, 2015-09-27
@IvanIlyasov

Che, for two years they did not give the right answer ???
Here:

RewriteCond %{REMOTE_ADDR} !93.143.174.0 
RewriteRule ^index.php$ index.html [L,QSA]

In this case, the main address should initially be index.php. And if the IP does not match, then it redirects to index.html
If you need to specify multiple IP addresses, use a regular expression like this:!^(93\.143\.174\.0|127\.111\.11\.111)

D
Dmitry, 2012-10-22
@Tomasina

tried but didn't work:
RewriteCond %{REMOTE_ADDR} !^93.143.174.* RewriteRule ^(.*)$ index.html [R,L]

V
vsespb, 2012-10-22
@vsespb

!^93.143.174.* - this should be a regexp. try !^93\.143\.174\.

G
grafomanych, 2012-10-23
@grafomanych

RewriteCond %{REMOTE_ADDR} !^(127).0.0.[0-9]+
RewriteRule ^(.*)$ index.html [L]

W
Wott, 2012-10-25
@Wott

# это регэксп, так что подсеть можно только /24 /16 или перечислением RewriteCond %{REMOTE_ADDR} ^192\.168\.(1|2|3|4)\. RewriteRule . /index.php [S=1] # тут делаем то что нужно для всех остальных RewriteRule . /index.html
Using the Skip flag, you can build any conditional constructions, while in the rule itself we divide the condition for the incoming url, and if you need something outside the url, such as an address, add the conditions above

W
Wott, 2012-10-25
@Wott

sorry tag mixed up

# это регэксп, так что подсеть можно только /24 /16 или перечислением 
RewriteCond %{REMOTE_ADDR} ^192\.168\.(1|2|3|4)\. 
RewriteRule . /index.php [S=1] 
# тут делаем то что нужно для всех остальных 
RewriteRule . /index.html

D
Dmitry, 2012-10-26
@Tomasina

error 500 crashes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question