2

I am trying to trim my htacess file. Other than the # lines is there any way I could make it smaller? It seems to be working as I was hoping as is. Cut I was hoping there might be a way to have more one ip per line, instead of doing one line for every ip address.

<Files 403.shtml>
order allow,deny
allow from all
</Files>
# -- MOD: Forbid Cross Site Scripting in query
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^.*(allow_url_include|auto_prepend_file).* [NC]
RewriteRule ^(.*)$ - [F,L]
</IfModule>
# -- END MOD: Forbid Cross Site Scripting in query
deny from 180.76.5.0/24
deny from 198.23.76.220

Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^(38\.100\.121\.65|206\.141\.173\.244|68\.14\.15\0./24)$
RewriteRule ^(.*)$ http://www.dog.com/$1 [L,R=301]

RewriteCond %{REMOTE_ADDR} ^(18\.10\.11\.51|106\.142\.130\.214|168\.114\.125\0/.24)$
RewriteRule ^(.*)$ http://www.cat.com/$1 [L,R=301]

<IfModule mod_rewrite.c>
RewriteRule ^About\-us\.php$ About\-Me\.php [R=301,NE,QSA,L]
</IfModule>
#RVS END REDIRECT PAGE  
Jake
  • 31
  • 2

1 Answers1

0

You can use:

RewriteCond %{REMOTE_ADDR} ^(38\.100\.121\.65|206\.141\.173\.244|68\.14\.150\.24)$

You have a problem with: ^68\.14\.15\0.24$ and ^168\.114\.125\0.24$

I think you want to use: ^68\.14\.150\.24$ and ^168\.114\.125\.24$

Croises
  • 18,570
  • 4
  • 30
  • 47
  • "You have a problem with: ^68\.14\.15\0.24$ and ^168\.114\.125\0.24$" . I am wanting it to redirect all 254 ips from that subnet – Jake Oct 18 '16 at 16:41
  • You can't use subnet mask in regexp test. You can only make a partial comparison, for example on the first 3 numbers, or with `[0-9][0-5]` – Croises Oct 18 '16 at 17:14
  • There was a typo ( corrected it in example). It was supposed to be 0/.24$ Is this the wrong string to use to included all 254 ips in redirect? – Jake Oct 18 '16 at 18:33
  • No way to add subnet mask in regex. You can use `^68\.14\.15` to test the 24 first bits. In this case, in RewriteCond, it's a string compare. – Croises Oct 18 '16 at 22:55
  • So you are stating there is no way to redirect an ip address range? – Jake Oct 18 '16 at 23:14
  • You can, but not with subnet mask: http://stackoverflow.com/questions/11653461/redirect-a-range-of-ips-using-rewritecond or http://stackoverflow.com/questions/24468660/apache-rewrite-subnet-ip-range – Croises Oct 19 '16 at 06:31