I am setting up a site that many different schools around the UK will log into.

Our client would like to have schools access areas that are normally restricted by login without having to log in by using their known IP address.

Is there a plugin out there that will effectively allow access to certain channels if an IP address matches one in a list (or from a range)? Alternatively, is there a plugin or method for automatically logging in users if their IP address matches one set somewhere in the admin?

Thanks, John.

  • Are you talking about setting a single, or single range, of IPs or setting different ranges? Are you wanting to allow 'valid' IPs to access a single area or will different IPs access different areas?
    – foamcow
    Apr 29 '14 at 13:44
  • Most likely a list of static IPs, but it'd be good to allow subnets (not essential).
    – John Hunt
    Apr 29 '14 at 14:08

Nothing comes to mind for a plugin specifically, but this is more of a job for the .htaccess file to handle. If you aren't familiar with all of the rules to apply, there is a great book available - http://htaccessbook.com

There's a few ways to approach this, the following is by no means providing perfect examples but just indicating the possibilities available.

I redirect visitors using the .htaccess file. This one for example will redirect visitors from Russia (^RU$) to another URL, in this case Google's front page.

RewriteEngine on    
RewriteRule ^(.*)$ http://google.com [R,L]

But you could of course redirect visitors to a page that handles information more suited to them or stating when they will be able to access the information at all.

Also, it can be used to redirect UK visitors to the correct location of the pages you wish them to solely see. So it can work both ways.

If it's required to use a known IP address, then the example line would be:

RewriteEngine on 
RewriteCond %{REMOTE_ADDR} ^55\.55\.138\.243
RewriteRule ^(.*)$ http://google.com [R,L]

If it were just a single unique IP address (usually a company IP) then you could use:

RewriteCond %{REMOTE_HOST} 123\.456\.789
RewriteCond %{REQUEST_URI} /requested-page\.html
RewriteRule .* /just-for-you.html [R=301,L]

There's an alternative to this which is the mod_rewrite rule.

<IfModule mod_rewrite.c>
      RewriteCond %{REMOTE_ADDR} ^111\.222\. [OR]
      RewriteCond %{REMOTE_ADDR} ^123\.456\.789\.0$
      RewriteRule .* http://example.com/right_location_for_UK_visitors [L,R=302]

The first condition is matching a range of IP's whilst the second is targeting a single IP address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.