Redirect folder if not ip

Using mod_rewrite to handle various content issues

Redirect folder if not ip

Postby Ulysses » Tue Mar 17, 2009 7:22 am

Hi,

I'm trying to secure a login area so as to allow whitelist users access, but redirect everyone else to the root of the site. Here is what I've got thus far, but it doesn't work (IPs are just examples):

Code: Select all
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^192\.100 [OR]
RewriteCond %{REMOTE_HOST} !^192\.200
RewriteRule ^admin/$ / [L]


The idea is to re-use this same htaccess file for numerous sites, so if it is possible, I would like to redirect unwanted visitors to the site root (/) rather than having to write the absolute path (http://www.mywebsite.com) for each website.

Your help would be much appreciated.

Thanks.
Ulysses
 
Posts: 10
Joined: Thu Sep 18, 2008 7:58 am

Postby richardk » Tue Mar 17, 2009 7:46 am

You either want to redirect if it IS 192.100.* OR it IS 192.200.* (a blacklist)
Code: Select all
RewriteCond %{REMOTE_HOST} ^192\.100 [OR]
RewriteCond %{REMOTE_HOST} ^192\.200


Or you want to redirect if it IS NOT 192.100.* AND it IS NOT 192.200.* (a whitelist)
Code: Select all
RewriteCond %{REMOTE_HOST} !^192\.100
RewriteCond %{REMOTE_HOST} !^192\.200


Then
Code: Select all
RewriteRule ^admin/$ / [R,L]

to make it redirect.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Ulysses » Tue Mar 17, 2009 8:15 am

Thanks Richard,

Your whitelist example works great, much appreciated.

Just a quick question if I may ... how would I go about making sure that any reference within the admin folder also redirect? at present the RewriteRule works only for the admin dir, but just in case somebody decided to guess admin/index.php for example, I would also like it to redirect.
Ulysses
 
Posts: 10
Joined: Thu Sep 18, 2008 7:58 am

Postby Ulysses » Tue Mar 17, 2009 8:22 am

Solved it, thanks:

Code: Select all
RewriteRule ^admin/(.*)$ / [R,L]
Ulysses
 
Posts: 10
Joined: Thu Sep 18, 2008 7:58 am


Return to Content

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron