• PHP
  • Ruby on Rails
  • MySQL
  • Linux
    • SELINUX
    • Fedora
    • debian
  • Apache
  • nginx
  • AJAX
Albertech.net

WordPress MU: Limit access to certain blogs

July 2, 2009 3:22 pm / Albertech.net

I recently implemented a way to limit access by IP range on specific blogs on WordPress MU. As you know, WordPress MU uses Apache Rewrite engine to rewrite URLs. For instance, you have a blog on WordPress MU called “intranet”. Apache Rewrite takes the “intranet” string in the URL and automatically rewrites it as a value in the PHP script. A side effect to Apache Rewrite is that “Directory” .htaccess parameters don’t work. So, if you wanted only your company IPs to access an internal blog, you will need to use Apache Rewrite parameters instead.

Here’s how to limit access to an IP or subnet on a particular blog on your WordPress MU install:

DISCLAIMER: Modifying .htaccess files can break your WordPress MU install. ALWAYS backup your .htaccess file. Simply, copy .htaccess file and rename it to .htaccess-backup. (cp .htaccess .htaccess-backup)

Step 1:

Add a section after the “RewriteEngine On
RewriteBase /…” section

RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.5
RewriteCond %{REQUEST_URI} ^/BLOG1
RewriteRule .* - [F]

DO NOT SAVE YET. You will need edit the IP address info and blog info first:

Step 2: Replace the 1.2.3.4 number with your company IPs (its easier if you have an entire subnet or you can use internal IPs)

For a class C, the part after {REMOTE ADDR} would be
!^1\.2\3\.

Step 3: Replace BLOG1 with the blog you want to limit access to those IPs. So http://www.mysite.com/myfirstblog would be “^/blogs/

Optional: If you have WordPressMU installed in a folder (e.g. not your root folder), you will need to append the directory in front of the blog name.

For instance, if you have http://mysite.com/blog (as your WordPress MU root folder) the ^/ BLOG1 would be

^/blog/BLOG1

Optional: Multiple blogs with same access restrictions
By default, the Apache Rewrite treats every line as an AND statement. If you have multiple blogs, you will need to have an [OR] at the end of the line.

RewriteCond %{REQUEST_URI} ^/BLOG1 [OR]
RewriteCond %{REQUEST_URI} ^/BLOG2

Errors?

  • Make sure you have ^/ marks in front of the blog names
  • IP addresses must have a backslash before each dot. Regular expression for dot is concatenate by default, so it needs to be escaped
  • Make sure you don’t forget the !^ sign before the IP, otherwise you will be forbidden.

If all else fails, if can’t fix the error, just copy back the .htaccess-backup to the .htaccess file.

Share this:

  • Facebook
  • Google
  • Twitter
  • Print
  • Email
Posted in: Apache, Linux, PHP / Tagged: limit access, wordpress mu

Comments are closed.

Post Navigation

← Previous Post
Next Post →

Categories

  • AJAX
  • Android
  • Apache
  • Canon Cameras
  • Cloud
  • CMS
  • Computer Mods
  • Conferences
  • Deals
  • debian
  • Fedora
  • Flash
  • Frameworks
  • git
  • Hardware
  • HTML
  • IDE
  • iPhone
  • iPhone App Review
  • jQuery
  • Linux
  • Mac OS X
  • MySQL
  • nginx
  • PHP
  • portfolio
  • Puppet
  • Ruby on Rails
  • Script Reviews
  • SELINUX
  • Software
  • Software Review
  • SQL Server
  • statistics
  • Tech
  • Tomcat
  • Uncategorized
  • VMWARE
  • VPS
  • Windows
  • wordpress
  • Zend Framework

Blogroll

  • DragonAl Flickr
  • Dropbox – Free 2GB Account
  • James' Blog
  • Javascript Compressor
  • PHP Builder Community
  • PHP-Princess.net
  • Rubular – Regular Expression Validator
  • The Scale-Out Blog
  • Tiny MCE

Tags

activation AJAX android antec Apache AWS awstats canon coda codeigniter debian enclosure external free G1 install vmware tools Internet Explorer iphone 5 jquery Linux mx-1 MySQL office 2007 OSX photoshop PHP plugin plugins portfolio redesigned website review rewrite script security SELinux ssh tinymce tutorial upgrade VMWARE vmware server wordpress wordpress mu XSS zend framework
© Copyright 2013 Albertech.net
Infinity Theme by DesignCoral / WordPress
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.