We're receiving a DDOS attack from a specific range of IPs (192.168.0-255.0-255). In our htaccess file we've attempted to forward their requests to a static HTML file but only half the requests are being blocked. Does anyone see why that would be?
RewriteCond %{REMOTE_ADDR} ^(10\.0\.0\.1|192\.168\.[0-9]{0,3}\.[0-9]{0,3})$
RewriteCond %{REQUEST_URI} [^/etc/blocked_ip.html]
RewriteRule ^(.*)$ /etc/blocked_ip.html [R=301,L]
and our access logs show:
2014-06-27 11:59:03 192.168.20.232 - 1.2.3.4 443 GET /etc/blocked_ip.html ?
2014-06-27 11:59:08 192.168.20.231 - 1.2.3.4 443 GET /video/832
Note: I've substituted the actual IP ranges with private ranges.
Thanks for any suggestions.
Actually your rewrite condition is incorrect:
RewriteCond %{REQUEST_URI} [^/etc/blocked_ip.html]
Probably you meant:
RewriteCond %{REQUEST_URI} !^/etc/blocked_ip\.html
You rule can be shortened to:
RewriteCond %{REMOTE_ADDR} ^(10\.0\.0\.1|192\.168\.[0-9]{1,3}\.[0-9]{1,3})$
RewriteRule !^etc/blocked_ip\.html$ /etc/blocked_ip.html [R=301,L,NC]
Also make sure this is your very first rule in your .htaccess.
Related
I'm trying to write a rule that means if anyone goes to any address across the whole domain, it will replace http: with https:
My current rule is;
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain.co.uk/members$1 [R,L]
This works for my main domain but I have different subdomains which I need to write to work in the same way. I'd ideally not like to write a rule for each of the subdomains.
If I go to https://example.mydomain.co.uk/members it shows the correct content but if I got http://example.mydomain.co.uk/members it redirects to https://mydomain.co.uk
Thanks in advance for your help!
EDIT: I forgot to mention, this rule is in my /members directory not root.
You could do this:
ServerAlias *.mydomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$
RewriteRule ^(.*)$ https://%1.mydomain.com/$1 [R=302,L]
try this:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I need to allow site access to only development team accessing from IPs 111.111.111.111 and 222.222.222.222 and for the rest of the visitors would like to show temporary maintenance page brb.html
I tried this with the following condition and rewrite rule and it got into a redirect loop. Any insights on how to make this work?
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^222\.222\.222\.222
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
RewriteCond %{SCRIPT_FILENAME} !^brb.html
RewriteRule ^.*$ /brb.html [R=307,L]
Note: IPs used above are not the real ones.
You can use:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^(222\.222\.222\.222|111\.111\.111\.111)
RewriteRule !^brb\.html$ /brb.html [R=307,L]
And test in a new browser.
!^brb\.html$ in rewrite rule pattern will stop looping for you.
SOLUTION:
Because of CloudFlare I had to use RewriteCond %{HTTP:X-FORWARDED-FOR} instead of RewriteCond %{REMOTE_ADDR}
I'm sure there is an easy answer to this question, but I've scoured through through available threads and its either not there or I'm too ignorant to recognize it starting in my face. This seems to be the answer, but I just can't configure correctly.
Question: How do I set up .htaccess so that all subdomains are forwarded to their https equivalents, while also allowing the main domain itself get ported to its https equivalent? In other words:
hxxp://subdomain1.domain.com --> hxxps://subdomain1.domain.com
hxxp://subdomain2.domain.com --> hxxps://subdomain2.domain.com
...and so on, but also...
hxxp://domain.com --> hxxps://domain.com
Current Configuration:
My .htaccess is set up to provide an unconditional forward as follows:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]
To achieve what I want, I would think that there must be some way to define a wildcard and pass the result of that wildcard as the subdomain - whether, subdomain1, subdomain2 or a value of nothing - to the actual redirect.
Any help would be much appreciated.
I haven't tested this, but it should allow you to capture the subdomain as well as the request.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(.*)\.yourdomain\.com$
RewriteRule ^(.*)$ https://%1.domain.com/$1 [R,L]
This rule however, will not work for requests that do not contain a subdirectory, so you actually need two rules.
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^yourdomain\.com$
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]
Goto your subdomain folder
Create .htaccess file in this folder
and paste this code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I'm making significant changes to my website today and want to display a maintenance page for everyone except for me. However, it also keeps redirecting me to the maintenance page even though I whitelisted my IP address (which I triple-checked by doing an ipconfig). I'm guessing something is wrong with my code. Here's my .htaccess file in case anyone can help!
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.playbank\.com$ [NC]
RewriteRule ^(.*)$ http://www.playbank.com/$1 [L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.*
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
192.168.1.* is your LAN network, which is a private network not visible to the rest of the Internet. You need to specify your external IP address, given by your ISP. Enter www.whatismyip.com and use that one.
I am using the code below within my .htaccess file to place my site into maintenance. Essentially what it does is to redirect anyone who is NOT from a specific IP address to a .maintenance. subdomain where I have a maintenance page up (thus allowing me to perform testing on the real site). My question is, how would I add a second IP address to the line:
RewriteCond %{REMOTE_ADDR} !^23\.254\.12\.43
to allow 2 IP's to come through? Is it as simple as just putting a space and using the same format as the first one? (Sorry in advance if it really IS that simple, but I haven't tested it due to fear it may appear to be working but really not). Thanks!
###################################################################
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^23\.254\.12\.43
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://maintenance.mysite.com [R=307,L]
####################################################################
Just adding another RewriteCond to handle the second IP address should be fine, like so:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !=23.254.12.43
RewriteCond %{REMOTE_ADDR} !=192.168.0.1
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://maintenance.mysite.com [R=307,L]