0

(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?

ggkmath
  • 4,188
  • 23
  • 72
  • 129
  • Possible duplicate of **[Restrict URL by IP range in .htacess?](http://stackoverflow.com/questions/13447362/restrict-url-by-ip-range-in-htacess)** Have a look. ;) – WASasquatch Apr 17 '14 at 04:18
  • Thanks for the link @WASasquatch. Correct me if I'm wrong, but the accepted answer doesn't solve this question (there's no URL address so they probably placed the htaccess file in a specific sub-directory, and I'm not sure what they're doing with `user` and `admin`), and the other answer was reported not to work. – ggkmath Apr 17 '14 at 04:26
  • [Restrict / Block Directory Based on IP Address][1] I think you may check this question [1]: http://stackoverflow.com/questions/9263896/restrict-block-directory-based-on-ip-address – xhg Apr 17 '14 at 04:34
  • Thanks @parsecool, what would I use for `/hidedirectory` in your link's answer? Recall that if my URL is `https://www.mycompany.com/locations/europe/contactus` there is not an actual folder at `/home/username/public_html/locations/europe/contactus/` due the nature of the CMS (concrete5). Or, should this `` also work for URLs? – ggkmath Apr 17 '14 at 04:43

1 Answers1

1

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]
xhg
  • 1,850
  • 2
  • 21
  • 35
  • Could you explain a little what lines 2 and 3 are doing? – ggkmath Apr 17 '14 at 04:56
  • 1
    the second line is to apply rule to IP `123.45.67.8 - 123.45.67.9` and third line is to set `/locations/europe/contactus/` to F(Forbidden) – xhg Apr 17 '14 at 05:01
  • What does the `^` refer to? Also, I want to block all IP addresses except my own. Is there a way, rather than specifying which IP addresses the rule applies to, to specify the rule applies to all IP addresses except a specific one (e.g. is `RewriteCond %{REMOTE_ADDR} !=111.222.333.444` valid syntax?)? – ggkmath Apr 17 '14 at 05:02
  • (http://www.webmasterworld.com/forum92/4332.htm), you may check this, I am not sure whether my expression is right, but you can try it, refer to (http://www.webmasterworld.com/forum92/4332.htm) – xhg Apr 17 '14 at 05:07
  • also try `RewriteRule ^locations/europe/contactus/ - [F]` and `RewriteRule ^locations/europe/contactus - [F]` (delete slash(s)), to see which works for you. – xhg Apr 17 '14 at 05:09
  • yes, of course, you can try `RewriteCond %{REMOTE_ADDR} =!111.222.333.444` – xhg Apr 17 '14 at 05:13