Restricting IP access to a specific website page

Joel86

Registered
Jan 28, 2020
2
0
1
Portugal
cPanel Access Level
Website Owner
Good morning, everyone. Mine is Joel Santos and I'm here with a little problem. The company I work for has a website with an online store and I would like to restrict this page only to some countries where we cannot sell. We cannot sell in those countries because there are stores that sell our products and we do not want to compete with them.
I'm not an expert in programming so I appreciate all the help given.
 

cPanelLauren

Forums Analyst II
Staff member
Nov 14, 2017
9,366
799
263
Houston
Hello @Joel86


There are a few ways to do this, the easiest might be to block the country from your site/server all together using the CC blocking of CSF (If you're using it).You can read about CC blocking with CSF here: Blacklisting Countries

You could also implement a ModSecurity rule for this but it would take some customization, we've got another thread on that here: ModSecurity Rule to Block Country for One Domain Only?

Alternatively, you could add an .htaccess to the folder where the store portion of the site lives and do a .htaccess block but the number of blocks you'd have to implement to block even one country would be pretty huge. There are some tools that can help with this, some helpful information might be found here: Block certain country using .htaccess
 

Joel86

Registered
Jan 28, 2020
2
0
1
Portugal
cPanel Access Level
Website Owner
Hello. Thank you for the quick answer. I just need to block the store page. Sorry but im not an expert but I'm looking at the last option. Is it possible to get some help?
 

keat63

Well-Known Member
Nov 20, 2014
1,548
140
93
cPanel Access Level
Root Administrator
Hi Joel

Are you a web site owner only.
Do you have access to Cpanel. ?

I'm not sure that you could impliment CSF or ModSecurity if you don't have access to WHM, (a web site owner wouldn't have this), and I don't believe CPanel has such a feature either.

I'd suggest trying to do something with your .htaccess file which resides in the root of your public_html folder.

This external web page might help you achieve this, it gives a step by step guide.

https://www.hostinger.co.uk/tutorials/htaccess/how-to-allow-or-block-visitors-from-specific-countries-using-htaccess

Good luck.

edit:

Just one thing i've considered, and could do with some clairification. !!

Be careful what you deny, don't be over zelous.
eg: if you were to deny the whole of the USA for instance, could you then also be denying something like GoogleBot, meaning your web site rankings might be affected.
 
Last edited:

Wallu

Member
Jan 13, 2020
15
3
3
Finland
cPanel Access Level
Root Administrator
Hi,

you should do this on the store app level, e.g. if you are using Woocommerce, just restrict buying in your shipping zone(s). This would enable you to also notify the customers outside your shipping zones to go to somewhere else (maybe your reseller in another country), and wouldn't restrict all access with "dirty" error or message that "you are not welcome here". Let them browse your goods, but go buy it from your local reseller in your own country for example. Any shopping / online store app should have similar options.

Now, all this assuming you really actually don't need to _block_ them, just restrict selling to these countries.

- Wallu