ggkmath
ggkmath

Reputation: 4246

htaccess: how to restrict IP Address for URL path?

(I don't think the above link provides an answer for this question; see comment below)

I'm using a CMS system that uses a database instead of the traditional file-directory structure to store/manage webpages. Since there's no folder for each webpage, I can't place an .htaccess file in specific folders to control access.

There is one .htaccess file that exists in the root directory. Is it possible to use that .htaccess file to restrict access by IP Address for a specific URL? If so, what's the syntax? Note, it must be for URL because I don't believe there is even a specific file with .html extension for a webpage with this CMS (it's all handled behind the scenes somehow).

For example, the .htaccess file is here:

/home/username/public_html/.htaccess

and the URL needing access control is here:

https://www.mycompany.com/locations/europe/contactus/

What's the code to place in the .htaccess file to only allow the IP Address of 111.222.333.444 (for example) access to the above URL?

If this isn't possible, is there another way to solve this problem for restricting IP Address to a specific webpage?

Upvotes: 0

Views: 5599

Answers (1)

xhg
xhg

Reputation: 1885

Using mod_rewrite to control access Here is the documentation of it, you may go to section "Blocking of Robots" to block IP range which trying to access particular url.

I think you may try this, I am not sure whether is works, but still try it, hope it works for you.

RewriteEngine on # this is for opening the module
RewriteCond %{REMOTE_ADDR} =123\.45\.67\.[8-9]
RewriteRule ^/locations/europe/contactus/ - [F]

Upvotes: 1

Related Questions