LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Apache Restrict Access to Specific URL Based on IP (https://www.linuxquestions.org/questions/linux-newbie-8/apache-restrict-access-to-specific-url-based-on-ip-4175435113/)

Obscurious 11-01-2012 01:54 PM

Apache Restrict Access to Specific URL Based on IP
 
I have a wordpress multi-site server running on Ubuntu. I need to restrict access to two of the wordpress sub-sites to a specific subnet. For example:

http://www.mywp.com/jobs
http://www.mywp.com/apples

These two subsites are only access via 192.168.*.* ( or in CIDR notation 192.168.0.0\16), and 104.113.*.*

I have explored many options the most promising is the apache mod_rewrite approach; however, I have found that rewriting works for directories. Wordpress doesn't have a typical tree stucture, i.e. http://www.mywp.com/jobs doesn't correspond to /var/www/jobs, and in fact http://www.mywp.com/jobs doesn't have a single file or directory representation at all. Thus thus there is no corresponding .htaccess file for /jobs. I don't see how to attach a URL instead of a directory to the rewrite rule. Here are the rewrite concepts I have been playing with:

Code:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REMOTE_ADDR} ^192.168\. [OR]
 RewriteCond %{REMOTE_ADDR} ^104\.113\. [OR]
 RewriteRule ^(/jobs*)$ / [F,L]
</IfModule>

Which is also backwards as far as restriction goes since this redirects ../jobs to the home page.

Code:

<Limit GET POST PUT>
 order deny,allow
 deny from all
 allow from 192.168.
 deny from 104.113.
</Limit>

Which makes more sense to me but still doesn't attach to a URL. Can anyone suggest methods for restricting access to a URL based on IP without a per directory or .htaccess approach?

larvel 11-01-2012 05:14 PM

Have you tried Location match?

Obscurious 11-01-2012 06:39 PM

Quote:

Originally Posted by larvel (Post 4820032)
Have you tried Location match?

Marvelous! This worked perfectly:

Code:

      <Location /jobs>
                Order deny,allow
                deny from all
                allow from 192.168.
                allow from 104.113.
      </Location>

      <Location /apples>
                Order deny,allow
                deny from all
                allow from 192.168.
                allow from 104.113.
      </Location>

Which yields a 403 Forbidden to everyone else. Thanks, I did not know this directive existed.


All times are GMT -5. The time now is 12:16 AM.