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]
Related
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
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]
all queries with site.com/p/QUERY are handled, but some users wrongly use site.com/QUERY for requests, and they see 404 error page.
how to redirect site.com/QUERY to site.com/p/QUERY and avoid 404 errors by .htaccess?
not found any solution for this case in htaccess tutorials and questions.
Use this
<Files index.php>
order allow,deny
deny from all
</Files>
# Turn on URL rewriting
RewriteEngine On
Options +FollowSymLinks
# Installation directory
RewriteBase /
# Allow these directories and files to be displayed directly:
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico|img|js|css|media)
# Rewrite all other URLs to /p/URL
RewriteRule ^([^/]+)$ /p/$1 [PT,L]
# Rewrite all other URLs to /p/URL or /p/some.html?var=1&var2=2
RewriteRule ^(.*)$ /p/$1 [PT,L]
ErrorDocument 500 /errors/notfound.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 403 /errors/notfound.html
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?operationtoad.com/.*$ [NC]
RewriteRule \.(rar|exe|zip|html)$ - [F]
</IfModule>
order deny,allow
deny from all
allow from ##.###.###.##
When I add a second or third person in on a second allow from line, they can see the main site, but they are unable to go to /notfound.html or /anonexistingfile.html - they will either see the apache starter page or they get a 500 error.
Now if I remove myself from this I just get apache test page on the root and 403 forbidden on the others.
Not really the answer but...
Instead of allowing IP, you can replace this by an htpassword.
And double check your RewriteRule condition, maybe a bug inside it.
I've tried to set up a htaccess redirect for everyone except me. It works fine...except that I have to write an exception for every file that the under construction page wants. This will take me a while and I'm certain there is a proper way to do it, I just cant find it.
I have tried this:
order deny,allow
deny from all
allow from 205.97.194.334
ErrorDocument 403 http://www.domain.com/page.htm
<Files page.htm>
allow from all
</Files>
But I get an internal server error
What I have now is this:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1
RewriteCond %{REQUEST_URI} !/mypage\.html$
RewriteRule .* http://www.domain.com/construct/mypage.html [R=302,L]
What can I add in this to allow everything in the /construct/ ?#
Thankyou
P.S. Can anyone tell me why the first attempt didn't work?
EDIT:
Ok I've added this, which allowed the files, however, it is only redirecting when the directory is entered. I.e. domain.com will redirect to the construction page, but domain.com/index.php and anything else will not redirect
# Redirect everyone who's not from your IP
RewriteCond %{REMOTE_ADDR} !00.00.00.00 [NC]
# Allow real files to be served
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !index.html$ http://subverb.net/construct/index.html [R=307,L]
If you want /construct to be available to everyone else, and you want them to be redirected to that URL when opening any other URL:
# IF not from your address
RewriteCond %{REMOTE_ADDR} !^123\.4\.5\.6$
# AND not for /construct directory
RewriteCond %{REQUEST_URI} !^/construct
# THEN sen them to /construct/index.html
RewriteRule (.*) /construct/index.html [R=307,L]