Intranet IP Lockdown - .htaccess

I only want people to access the intranet from my IP.
I have searched different blogs as well but not get more.
I just want my website to be accessed by just my IP address to make it secure. I need an intranet that can be locked down by IP.

Try adding this to the .htaccess file in your web document root folder (often public_html or htdocs), changing the 999... to your IP address:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^999.999.999.999
RewriteRule ^ - [F]
This assumes that mod_rewrite is both installed and activated for htaccess files.
If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All

Related

about blocking a country by using .htaccess

I have tried many times, I feel desperate.
I have been able to do this successfully before on Apache 2.2.
Now my environment is Apache/2.4.18 (Ubuntu) Server
I go to https://www.ip2location.com/blockvisitorsbycountry.aspx to generate code
select ipv4
select China
select "Apache 2.4 .htaccess deny"
Then add the code to the bottom of .htaccess.
However, the result is that I cannot access the website whether I use a VPN or not.
I am located in Chinaļ¼Ž
Later, I tried to select another one country, such as Japan, to generate new blocking code.
However, the result was the same, after adding the code into .htaccess.
I also cannot access the website, even though the blocked country is Japan and I am in China.
I doubt the code, what should I do in order to get the right blocking a country code?
Some of the generated code:
<RequireAll>
Require all granted
Require not ip 1.0.1.0/24
Require not ip 1.0.2.0/23
Require not ip 1.0.8.0/21
Require not ip 1.0.32.0/19
Require not ip 1.1.0.0/24
Require not ip 1.1.2.0/23
Require not ip 1.1.4.0/22
:
now,I have solved the problem.
first of all,
the code generated from https://www.ip2location.com/blockvisitorsbycountry.aspx is 100% correct!
the reason why I cannot access the website whether using VPN or not,is that I didnot add the following code to yourdomain.conf to make https(ssl) url also support rewrite.
<VirtualHost *:443>
.......
<Directory "/var/www/html/yourdomainname/public_html">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Another solution using GeoIP and .htaccess
I have hostinger server
To enable GeoIP, all you have to do is add the following line to your .htaccess file:
GeoIPEnable On
Once added, you can verify if it's working by creating a PHP Info file and checking the PHP Variables section:
Image showing GeoIP is enabled in your server
How to use it?
To block access for perticular file in Britain, US and India:
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(GB|US|IN)$
RewriteRule (wp-login|xmlrpc).php$ - [F,L]
To allow access for whole website in Canada, UAE and India:
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CA|AE|IN)$
RewriteRule ^(.*)$ - [F,L,QSA]

Can't seem to get .htaccess to only allow my IP

I have my .htaccess setup as
order deny, allow
deny from all
allow from 123.my.ip
my IP is what ipchicken is giving me yet I am getting internal server error from any address. I have also tried multiple IP locations.
Following Apache copied from there site with this format just gives me forbidden even from my address...
Order Deny,Allow
Deny from all
Allow from my.ip.address
I have followed this question with no success...
.htaccess block all but my ip
I have also tried below from the following link with the same results...
http://kb.siteground.com/how_to_redirect_all_visitors_except_your_ip_to_another_site/
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^1.2.3.4
RewriteRule .* http://www.anothersite.com [R=302,L]
Just in case its relevant, i'm running magento on a AWS server. Running out of ideas to try...
If you tried:
order deny,allow
deny from all
allow from {111.111.111.111} <-- example ip
its very straight forward that it should be working
what you need to do is enable rewrite.log in your apaches virtualhost config
to determine whats going on in there with mod rewrites/
make sure that you have given your apache virtuahost auth to read from .htaacess file
** Override to All
you shouldn't use mod_rewrite rules to disallow any ip but your, keep that for specific page rewriting, the above code should be fine.
Make sure! that you're IP address is your Internet ip address and not an internal ip address. Go on google and type in "what is my ip" it should give you the correct one
if none works, there's definitely something funky going on with your .htaccess file. Try to paste your entire .htaccess file to somewhere where we can all view it. There may be errors on your .htaccess file. Make sure magentos admin isn't over-writing your .htaccess file.
with .htaccess its a big factor where you place the rules. sometimes having too many things on there can confuse the web server if its not in order.

external site using my css and image files, can I block this

each month many gigabytes of traffic on my site is being consumed by various sites, mostly in italy according to my stats. On further review of my raw access logs, they have built in direct reference links to css and png files in my site. I can just rename them but that wont stop them accessing a page in my site to get their full urls and keep accessing them.
Is there a way to block access to css and image files in my site unless they come from the same domain, somehow?
Regards
Greg J
Try adding this to the .htaccess file in your web document root folder (often public_html or htdocs) (edit the name of the domain):
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^yourdomain\.com
RewriteRule (?:jpg|png|gof|css) - [F]
This assumes that mod_rewrite is both installed and activated for htaccess files.
If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All

Redirecting web content but not the name of web page address

I have two internet addressess, say one.com and two.com
The content of my webpage is all under the domain one.com. If I hit address two.com I want it to redirect to one.com but still with address two.com. For example if I type in address bar two.com/article. I want to still show this same address but the content displayed would be as from address one.com/article
I tried to use htaccess file, but still no luck.
Any advice would be appreciated.
You can't achieve that while performing an external redirect.
If both domains are hosted on the same server, then you can perform an internal redirect (e.g. using Apache's Alias, AliasMatch or mod_rewrite).
If the domains are hosted on different servers, then you would have to proxy one of them. You could do this with ProxyPass from Apache's mod_proxy.
Go to your domain name provider and create an alias (CNAME record) for the address.
You will need to enable mod_proxy in your Apache config for that. Once mod_proxy is enabled, enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory on domain2.com host:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$ [NC]
RewriteRule ^ http://www.domain1.com%{REQUEST_URI} [L,P,NC]

.htaccess file 404 error with parallel plesk server

I have my .htaccess file working in localhost. But its not working if i upload it in server. It throws me 404 error.
I am using Parallel Plesk 11.0.9 and i can't find conf file for the same on that. If anyone has any idea how to fix it or any workaround for url rewriting would be great help.
Anyway here's the code in htaccess:
RewriteEngine on
RewriteRule ^store/living/Hutches-Armoires-Side-tables-Coffee-tables-Entertainment-centers? store.php?store=Living
RewriteRule ^store/dining/sideboards-buffets-chairs-benches-Dining-table$ store.php?store=Dining
RewriteRule ^store/working/Bookshelves-Study-tables$ store.php?store=Working
RewriteRule ^store/accessories/Boxes-Photo-Frames-Mirror-Frames-Block-Stamps-and-Book-stands$ store.php?store=Accessories
RewriteRule ^store/hallway/Console-tables-Armoires$ store.php?store=Hallway
RewriteRule ^store/sleeping/Bed-Frames-Night-Stands-Dressers-Mirror-framesBed-Linens-Canopies-Curtains$ store.php?store=Sleeping
You may need to wrap your rewrite rules with:
<IfModule mod_rewrite.c>
...
</IfModule>
...probably a good idea anyway.
Or you could try putting your rules into a vhost.conf file in the conf directory immediately below the location of your httpdocs directory. For example on a Centos machine the web root might be
/var/www/vhosts/domain.com/httpdocs
and you should have a:
/var/www/vhosts/domain.com/conf
directory, this will contain a set of pregenerated Apache config files that Plesk creates. If there isn't already create a vhost.conf and add your rules between a set of
<Directory /var/www/vhosts/domain.com/httpdocs/ >
... your rules ...
</Directory>
Once you've created the vhost.conf file you will need to tell plesk about it with
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain.com
If you still can't get it to work you can add a log for mod_rewrite, see this relevant SO answer for details
Is your Plesk running IIS and supporting PHP via FastCGI or ISAPI? If that is the case, check whether URL Rewrite is installed and follow this guide to translate htaccess (for apache) into web.config (for IIS)

Resources