Order Deny,Allow
Deny from all
Allow from 158.181.2.89
http://www.myip.ru/get_ip.php?loc= - i see my ip here
and i write it to allow myself only, but others ip to block, i can't understand why i can't allow that ip to enter??
$ip = $_SERVER['REMOTE_ADDR'];
$array = array('192.168.0.1', '212.112.96.6');
if (!in_array($ip, $array)) {
exit("Вход воспрещён <p>Ваш IP ".$ip."</P>");
i have tried this method, but it looks like many times other people have the same ip as me
change
Order Deny,Allow
to
Order Allow,Deny
I do not understand why it is not working.
Although you can try this If you have a static IP.
set Deny from all to Allow from all. remove Allow from 158.181.2.89.
Add this to your .htaccess in DocumentRoot
RewriteEngine on
RewriteBase /
RewriteCond %{REMOTE_ADDR} !xxx\.xxx\.xxx\.xxx
RewriteRule ^ - [F]
F is for forbidden. rerplace the xes in xxx\.xxx\.xxx\.xxx by your corresponding Ip-addr.
Related
i want a change the .htaccess file to hide the url parameters .
I would like to accept urls like
http://www.demo.com/74874 , that means http://www.demo.com?code=74874
You didn't mention what operating system you are using and instruction can vary, plus you didn't say if your are using HTTPD and if mod_rewrite is already installed/enabled. Assuming mod_rewrite is enabled and AllowOverride FileInfo is set in the server config, you could use this in your .htaccess:
RewriteEngine on
RewriteRule ^/([0-9]+) ?code=$1
This will accept any number as the path and rewrite it with the query string. If you want to keep any existing query string parameters, you would need to add [QSA] to the end of the RewriteRule.
I have a site where subdirectories are generated automatically, and need to be indexable under .htaccess
However, I don't want someone to be able to go to the root of these subdirectories and to view them all. I also don't want anything other than these subdirectories to be indexable.
E.g.
/ ~ Has "Options -Indexes" (Non-Indexable)
/foo/ ~ Has "Options -Indexes" (Non-Indexable)
/foo/bar/ ~ Has "Options +Indexes" (Indexable)
/foo/baz/ ~ Has "Options +Indexes" (Indexable)
It's not possible for me to generate an individual .htaccess file for every subdirectory individually, the system I'm using doesn't support it.
I'm assuming there's no other way to solve this problem (without possibly using the Apache config), so I'm just allowing the index recursively (i.e. from /foo), then inside /foo 's .htaccess file:
Options +Indexes
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/foo[/]?$
RewriteRule (.*) / [R=301,L]
To just redirect people to the homepage. Also put a meta refresh redirect in there just incase.
I think that this is a 'quite a basic question' but how do I allow two IP Addresses to permit entry:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
# ENTER IP HERE
RewriteCond %{REMOTE_ADDR} !^134.139.212.198$
RewriteRule ^(.*)$ - [R=403,L]
</IfModule>
Can I just simply copy paste the line below where it says # ENTER IP HERE
I just want to know how to do it properly.
Thank you!
It's just copied and paste the same line.
Option #1: define all IP
Here's the only way to do it:
Allow from 145.50.39.8
Allow from 145.50.39.9
Allow from 145.50.39.10
Allow from 145.50.39.11
Allow from 145.50.39.12
Allow from 145.50.39.13
Allow from 145.50.39.14
Allow from 145.50.39.15
Allow from 145.50.39.16
Allow from 145.50.39.17
Option #2: use a partial IP
If you want something more generic, you can use a partial IP:
Allow from 145.50.39
But this will allow IP from 145.50.39.0 to 145.50.39.255.
Option #3: use a netmask or a CIDR
To get even closer, you can use a netmask or a CIDR:
Allow from 145.50.39.0/255.255.255.224
or
Allow from 145.50.39.0/27
This will allow IP from 145.50.39.0 to 145.50.39.31.
I would really appreciate anyone's help with a mod_rewrite question. I don't know regex and am not familiar with .htaccess directives, so I can't think of how to solve the problem I am having.
Below is a description of what I am trying to accomplish...
3 websites:
http://www.example.com/ or http://example.com/
http://east.example.com/
http://west.example.com/
Have pages on main site that need to be redirected to other sites:
http://www.example.com/location1
http://www.example.com/location2
http://www.example.com/location3
http://www.example.com/location4
http://www.example.com/location5
http://www.example.com/location6
Need to redirect some pages to one website based on location, e.g http://east.example.com/:
http://www.example.com/location1 redirect to http://east.example.com/location1
http://www.example.com/location2 redirect to http://east.example.com/location2
http://www.example.com/location3 redirect to http://east.example.com/location3
(also without www) e.g.
http://example.com/location1 redirect to http://east.example.com/location1
Need to redirect some pages to another website based on location, e.g http://west.example.com/:
http://www.example.com/location4 redirect to http://west.example.com/location4
http://www.example.com/location5 redirect to http://west.example.com/location5
http://www.example.com/location6 redirect to http://west.example.com/location6
(also without www) e.g.
http://example.com/location4 redirect to http://west.example.com/location4
Want a rewrite rule that works like:
If domain name is www.example.com or domain name is example.com
And domain name is not east.example.com
And domain name is not west.example.com
And "somelocation" (in the east) is in the URL
Then Rewrite(Redirect) URL to http://east.example.com/.../somelocation/.../somepage
NOTE: the three websites actually share the same codebase, so the URLs all point to the same location/.htaccess file. So, I tried using a basic redirect, and ended up with an error that said... can't open page because of too many redirects.
If anyone knows the answer and can help with this, I would really appreciate the help!
EDIT: Example of expected results
Original URL:
"http://www.example.com/locations/eastend-web-page"
Rewritten URL:
"http://east.example.com/locations/eastend-web-page"
Please try to fill a rewritemap file (see here) to make a correspondance with the URLs that are part of your "east" domain. You may declare it like this:
RewriteMap mapmaintoeast \
dbm:/web/htdocs/yoursite/rewriterules/mapmaintoeast.map
Regarding your sample, your map file may be filled with things like:
eastlocation1 mainlocation1
eastlocation2 mainlocation2
eastlocation3 mainlocation3
...
I've called them 'east' and 'main' to distinguish clearly. These examples are supposed to be URLs.
Do the same for west:
RewriteMap mapmaintowest \
dbm:/web/htdocs/yoursite/rewriterules/mapmaintowest.map
In that file:
westlocation1 mainlocation4
westlocation2 mainlocation5
westlocation3 mainlocation6
...
Then here you go for the hard part:
# This cond put any non-empty string into "%1" (= parenthesis + first cond):
RewriteCond %{QUERY_STRING} (.+)
# The following rule doesn't touch the URL, but
# will try to search into the map file and
# create fill an environment variable called MAINTOEAST with the
# string found and if not found, assign MAINTOEAST to "notfound"
RewriteRule . - [QSA,E=MAINTOEAST:${mapmaintoeast:%1|notfound}]
# if MAINTOEAST not empty and different from "notfound":
RewriteCond %{ENV:MAINTOEAST} !^$
RewriteCond %{ENV:MAINTOEAST} !(notfound)
# ok found => redirect to east:
RewriteRule (.*) http://east.example.com$1 [QSA,R=301,L]
# Now do the same with west (no comments needed (see previous)):
RewriteCond %{QUERY_STRING} (.+)
RewriteRule . - [QSA,E=MAINTOWEST:${mapmaintowest:%1|notfound}]
RewriteCond %{ENV:MAINTOWEST} !^$
RewriteCond %{ENV:MAINTOWEST} !(notfound)
RewriteRule (.*) http://west.example.com$1 [QSA,R=301,L]
This should work.
I hope I've given you enough clues to finish the job ;)
If you don't have enough clues...
Two hints:
Please try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)
RewriteEngine On
# If domain name is www.example.com or domain name is example.com
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
# And "somelocation" (in the east) is in the URL,
# Then Rewrite(Redirect) URL to http://east.example.com/.../somelocation/.../somepage
RewriteRule ^(.*somelocation.*)$ http://east.example.com/$1 [R,L]
You'd need to do the same thing for west. Note that if the domain name is www.example.com or example.com, it cannot be east.example.com or west.example.com
I need to rewrite this rules (from apache's .htaccess):
<files "*.*">
Allow from 84.47.125.0/19 66.211.160.0/19 216.113.160.0/19
Deny from All
</files>
To lighttpd ones, to allow the access to my /pswd directory only for those IP's:
84.47.125.0/19, 66.211.160.0/19, 216.113.160.0/19
How can I do that in lighttpd?
I've never used lighttpd but I've found this on Google:
http://www.cyberciti.biz/tips/lighttpd-restrict-or-deny-access-by-ip-address.html
It has an example for blocking access for 2 IPs and for blocking a single IP. It should be easily adaptable for you by doing this:
# vi /etc/lighttpd/lighttpd.conf
and then:
$HTTP["remoteip"] !~ "84.47.125.0/19|66.211.160.0/19|216.113.160.0/19" {
$HTTP["url"] =~ "^/pswd/" {
url.access-deny = ( "" )
}
}