Zen Cart Logo
Forums / General Questions / .htaccess code to only allow access to my IP address?

.htaccess code to only allow access to my IP address?

Views: 3,635

Results 1 to 17 of 17
3 Apr 2013, 12:54 PM
#1
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

.htaccess code to only allow access to my IP address?

Is there any code I can add to the .htaccess file on my development site to only allow access to the admin IP address? i.e only allow access to the store to the admin when logged into the admin area?

3 Apr 2013, 1:23 PM
#2
thanhv avatar

thanhv

New Zenner

Join Date:
Apr 2012
Posts:
7
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

Order Deny,Allow
Deny from all
Allow from adminip

I was test with my site http://trihung.com

3 Apr 2013, 1:28 PM
#3
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

thanhv:

Order Deny,Allow
Deny from all
Allow from adminip

> 
> I was test with my site <http://trihung.com>

so the .htaccess dynamically knows what 'adminip' is??
3 Apr 2013, 1:30 PM
#4
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

nope.. that doesnt work

im assuming you are meaning to hard code in my ip.. my ip changes, I want it to allow based on the current admin ip.

anyone else know how to achieve this?

3 Apr 2013, 2:10 PM
#5
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: .htaccess code to only allow access to my IP address?

You could try putting the site into "maintenance" mode. This will by default only allow the IP Addresses you add in the admin area to browse the store. Although if I remember correctly some features such as downloadable products do not always work in "maintenance" mode. You could also just go in via SFTP / FTPS and edit the allowed IP address each time.

If you just don't want search engines to crawl / index the site you can add a robots.txt to request they ignore all URLs on your site / folder.

If you do not want the world to access your development site:

  1. Site on a PUBLIC facing webserver, use static IPs on the clients and configure to allow only those IPs.
  2. Site on a PUBLIC facing webserver, use a authentication method (Apache or another method).
  3. Move the development site to a NON-PUBLIC facing webserver, use VPN / SSH Tunnel / etc to access network remotely. This lets multiple team members work on the website at the same time. In conjunction with version control (such as GIT / SVN) and project management software this works well.
  4. Move the development site to your local computer, block external requests. Good for local testing of websites + email generation.
    I do a combination of the last two... I test my changes locally and when done: commit to VCS (in my setup this goes to a shared development server for regression + unit testing) and log my changes to the PM software. In a few cases I have had a business need for a PUBLIC facing webserver for testing, but it is rare.
3 Apr 2013, 2:18 PM
#6
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: .htaccess code to only allow access to my IP address?

philip937:

nope.. that doesnt work

im assuming you are meaning to hard code in my ip.. my ip changes, I want it to allow based on the current admin ip.

anyone else know how to achieve this?

Set up to use a 'Dynamic DNS' and use hostname instead of IP address in the 'Allow From'

Alternatively, ask your ISP the range of IP addresses from the pool they assign to you and allow only those IP's. (keeping in mind that this will still allow anyone using the same ISP as you 'unrestricted' access.

If you prefer to keep things simpler, just restrict the admin folder(s) via a .htaccess password. It's just as secure, with little chance of locking yourself out.

Cheers
Rod

3 Apr 2013, 3:26 PM
#7
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

How does the store front look in maintainance mode? Is there just access to a single holding page unless you are admin? Where are the ip addresses set?
Thanks

3 Apr 2013, 5:46 PM
#8
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

just tried it, down for maintenance is perfect, does exactly what I need :o)

4 Apr 2013, 4:19 AM
#9
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: .htaccess code to only allow access to my IP address?

philip937:

How does the store front look in maintainance mode? Is there just access to a single holding page unless you are admin?

Yes (as you have discovered).

What you may not realise is that this page can be customised. Darnit. I forget the name of the file.

philip937:

Where are the ip addresses set?
Thanks

This is set by ZenCart based on the IP address of the admin user currently logged in (I think).

I don't know when this gets reset, but I'd assume that if you happened to lose connection to your ISP whilst in maintainance mode and get assigned a new IP address you could find yourself locked out of the system (Don't panic, this would be rare, and there are ways to recover)

Cheers
Rod

4 Apr 2013, 7:35 AM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: .htaccess code to only allow access to my IP address?

No, you wouldn't lock yourself out. All you'd need to do is login to your Admin (since maintenance mode only affects the storefront) and update the list of IPs which are allowed to bypass maintenance mode. Admin->Configuration->Website Maintenance.

4 Apr 2013, 7:41 AM
#11
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: .htaccess code to only allow access to my IP address?

DrByte:

No, you wouldn't lock yourself out. All you'd need to do is login to your Admin (since maintenance mode only affects the storefront) and update the list of IPs which are allowed to bypass maintenance mode. Admin->Configuration->Website Maintenance.

Doh! Rather obvious now you've explained it. :)

Cheers
Rod

4 Apr 2013, 7:53 AM
#12
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

The only consideration is that certain shipping and payment modules do not function when the site is in maintenance mode - so these must be tested in a "live" site.

But yes... the IP-restricted maintenance mode is one of zencart's most useful features.

5 Apr 2013, 10:44 AM
#13
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

thanks guys, I dont need it for testing i'll just simply disable maintanance mode when testing. however im pretty sure I was logged into the admin when I got the maintancance screen up so not sure im understanding about he admin being able to browse with the limited functionality?

anyone work out how you customise the page that shows? currently on my set up it shows the head navigation and a few other bits, but this may be my template and me hacking it too bits :p

5 Apr 2013, 3:07 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: .htaccess code to only allow access to my IP address?

philip937:

not sure im understanding about he admin being able to browse with the limited functionality?When you supply a list of authorized IP addresses and turn on maintenance mode, then anyone visiting from that IP will still see the shop as (almost) normal despite it being down for maintenance. It's not really got specific "limited" functionality, but rather will show a messageStack banner message indicating that the store is in maintenance mode.

While some might argue that older versions didn't support testing of external services while in maintenance mode, that old "limitation" is more related to those individual services than to maintenance mode itself.

philip937:

anyone work out how you customise the page that shows? currently on my set up it shows the head navigation and a few other bits, but this may be my template and me hacking it to bits
You can control many of those things in the Website Maintenance configuration screen. And if that's not enough control, there's the template file for the maintenance page ... which follows the same naming convention as all other template files.

6 Apr 2013, 7:09 AM
#15
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

DrByte:

When you supply a list of authorized IP addresses

Hey DeByte. Where do I supply the IP addresses?

6 Apr 2013, 7:31 AM
#16
gilby avatar

gilby

Totally Zenned

Join Date:
Aug 2005
Location:
Vic, Oz
Posts:
1,816
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

philip937:

Hey DeByte. Where do I supply the IP addresses?
on the same "Website Maintenance configuration screen" that Dr Byte mentioned

6 Apr 2013, 12:51 PM
#17
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: .htaccess code to only allow access to my IP address?

ah ok, must have missed that completely! cheers