I have follow problem:
I want to ban some user by ip and use for it .htaccess :
ErrorDocument 403 http://somedomen.com/index.php/errorpage
order allow,deny
deny from 1.2.3.4
allow from all
it blocks, but not redirect, site based on joomla. Maybe somebody has a suggestion?
I think your code should be this way round based on your order Allow,Deny
ErrorDocument 403 http://somedomen.com/index.php/errorpage
order allow,deny
allow from all
deny from 1.2.3.4
deny from 5.6.7.8
However the deny syntax does not generate an error 403 it just blocks the connection.
You could try this instead. I am not a rewrite expert and this is not tested so have a care.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^1\.2\.3\.4 [OR]
RewriteCond %{REMOTE_ADDR} ^11\.22\.33\.44 [OR]
RewriteCond %{REMOTE_ADDR} ^111\.222\.333\.444 [OR]
RewriteCond %{REQUEST_URI} !^index.php/errorpage
RewriteRule .* /index.php/errorpage
</IfModule>
Translation:
IF their IP address is 1.2.3.4
OR their IP address is 11.22.33.44
OR their IP address is 111.222.343.444
AND the request is not for index.php/errorpage
THEN display the index.php/errorpage page
Related
The following rule is allowing only www.google.com domain to access the file list.txt
My question, how can I change the rule to restrict www.google.com and allow other domain?
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(?:www\.)?google\.com$ [NC]
RewriteRule ^list\.txt$ - [NC,F]
</IfModule>
I want the browser response to 404 but not denied response.
Please test and see if this does what you want?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?google\.com$ [NC]
RewriteRule ^list\.txt$ - [NC,R=404]
but this might be clearer:
<Files "list.txt">
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?google\.com$ [NC, R=404]
</Files>
I left out <IfModule mod_rewrite.c> for clarity. If the module is not enabled, you might however prefer the server to not start opposed to just allow access.
I am NOOB. I am attempting to redirect specific IP addresses using htaccess to a different domain. Those ip addresses are of people copying what I type to describe stuff and put it on their site within a few hours. I want them to just see static site B while everyone else sees dynamic site A.
The code below is redirecting to cat.com which I used earlier as a test to redirect, which seemed to be working. But then I changed it to dog.com but but it is still redirecting me to cat.com. I had put a # symbol in front of the old rewriterule so it should not be in play anymore. I also checked the redirects in cpanel. This is a subdomain I am working with, not the main domain on the account. This htaccess file added only 68.14.155.149 to the redirects section nothing else.
<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$ [OR]
RewriteCond %{REMOTE_ADDR} ^206\.141\.173\.244$ [OR]
RewriteCond %{REMOTE_ADDR} ^68\.14\.15\0.24$
RewriteRule ^(.*)$ http://www.dog.com/$1 [L,R=301]
#RewriteRule ^(.*)$ http://www.cat.com/$1 [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^About\-us\.php$ About\-Me\.php [R=301,NE,QSA,L]
</IfModule>
#RVS END REDIRECT PAGE
Currently I'm blocking certain users IP addresses using
<Limit GET POST>
order allow,deny
allow from all
deny from 3.0.0.0/8
deny from 4.0.0.0/8
deny from 5.152.184.0/21
deny from 6.0.0.0/7
deny from 8.0.0.0/7
deny from 11.0.0.0/8
</Limit>
Which then once the 403 error is triggered, is redirecting them to a new domain using
ErrorDocument 403 http://www.domain.com
My question is instead of 403 redirecting them to the external domain, simply do a 301 redirect for the given url to the new domain.
Basicall, how can I trigger this code
RewriteCond %{HTTP_HOST} \olddomain.com$
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
For the IP addresses which I am denying?
You can get rid of your <Limit> container and use mod_rewrite like this:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(GET|POST)$
RewriteCond %{REMOTE_ADDR} ^((3|4|6|8|11)\.|5\.152\.(184\.185\.186\.187\.188\.189\.190\.191))
RewriteCond %{HTTP_HOST} olddomain\.com$
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
I'm trying to make a .htaccess redirection that can do the following things:
Redirect page A to page B;
Redirect all traffic except my IP.
Can you pls help me?
Where to Redirect
ErrorDocument 403 [Where to Redirect to]
order deny,allow
Block Everyone
deny from all
Except for...
allow from [YourIPGoesHere]
Full Code Example:
ErrorDocument 403 http://www.google.com/
order deny,allow
deny from all
allow from 173.194.41.134
Edit:
You can also try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^173\.194\.41\.134
RewriteCond %{REQUEST_URI} !/somethingHere\.html$
RewriteRule .* /somethingHere.html [R=302,L]
I have a site, say www.test.com. Now I need to get see the site only by typing the IP address, i.e. 102.3.0.2/index.php.
For that, what I need to change in my htaccess file?
Following is my htaccess file code:
#Options +FollowSymLinks
RewriteEngine on
#RewriteBase /cash-flights/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond $1 !(^index\.php|gif$|jpg$|jpeg$|JPG$|JPEG$|GIF$|PNG$|BMP$|png$|bmp$|js$|php$|htm$|html$|css$|ttf$|txt$|pdf$|swf$|flv$|robots\.txt$|video_chat$|.ico$)
#RewriteRule ^(?!js\/tinymce)(.*?)(\.html|\.php|\/)?$ index.php/$1 [NC,L]
RewriteRule ^(?!phpinfo\.php)(?!js\/tinymce)(?!turkeyMap)(?!cron_home)(?!quote_by_sms)(?!paypal)(?!supporttrio)(?!12all)(?!system\/application\/libraries\/libgmap)(.*?)(\.html|\.php|\/)?$ index.php/$1 [NC,L]
RewriteRule ^(.*)$ - [NC,L]
#php_value session.gc_maxlifetime 86400
<Files 403.shtml>
order allow,deny
allow from all
</Files>
deny from 100.200.200.200
Options -Indexes
Don't know if this is the reason why you are not getting it, but the ip has to be four numbers.
I.E. 102.1.10.1.
Any site name ex: www.test.com must be translated to an ip, if you can reach the site using a name you can also reach it using the ip address.
RewriteCond %{HTTP_HOST} !=123.456.789.101
RewriteRule ^(.*)$ http://123.456.789.101$1 [R,L]
But it can easily be bypassed by editing the value of the HOST HTTP header.