Forum Moderators: phranque

Message Too Old, No Replies

Redirect for every IP but my IP address

.htaccess redirect modrewrite

         

JamesTrix

8:30 am on Jan 19, 2008 (gmt 0)

10+ Year Member



My website is in the following format

/index.html with a simple splash screen and html link to /forum
/forum/

I am about to do some development work and setup a CMS in the root folder and wanted to hide it from others while I develop the site.

I wanted to set it up so that any user apart from a list of 1 or 2 ip addresses would just get redirected to the following url /forum/

The list of users would be able to access the CMS installed in the root folder.

(I dont want to rewrite the content just redirect) my site can be found on both [site.com...] and [site.com...]

Is that possible to do in the .htaccess file?

machonemedia

10:46 am on Jan 19, 2008 (gmt 0)

10+ Year Member



I would recommend developing the site on a local server (there are many packages if you can't setup one up manually to match your live server).

If you can't do that, then I think you don't even need htaccess, through PHP or other scripting languages you can access a users IP, just make an array and if it doesn't match your IP array, redirect using header(); or equivalent in whatever scripting language you use.

JamesTrix

12:03 pm on Jan 19, 2008 (gmt 0)

10+ Year Member



Good thinking if you don't think it can be done with the .htaccess I guess I can do it with PHP

I set my default document in Apache to be indexdev.php

And do some thing like this (I am not that hot with PHP) if some one could should me how to use an ARRAY this would be the basic code I guess.

Or is there a better what to do it?

<?php

$ip_dev_list=array(
"132.105.243.227",
"132.105.243.228",
"132.105.243.229"
);

if ( getenv("REMOTE_ADDR")!= in_array($ip_dev_list) )

header("Location: header("Location: [mysite.com...]
else

header("Location: [mysite.com...]
?>

[edited by: JamesTrix at 12:35 pm (utc) on Jan. 19, 2008]

jdMorgan

6:53 pm on Jan 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In example.com/.htaccess

# If not remote IP address 1
RewriteCond %{REMOTE_ADDR} !^24\.13\.0\.456$
# And if not remote IP address 2
RewriteCond %{REMOTE_ADDR} !^64\.35\.12\.890$
# Then redirect requests for anything except URLs in the /forum
# subdirectory to the home page of the /forum subdirectory
RewriteRule !^forum/ http://www.example.com/forum/ [R=301,L]

This assumes that you already have other working rewrite rules; The "setup" for mod_rewrite is not shown.

Jim

JamesTrix

1:28 am on Jan 20, 2008 (gmt 0)

10+ Year Member



jdMorgan I just wanted to say thank you very much for the example it worked perfectly and was just what I was looking for. Thank you very much for taking the time to post the example.