Forum Moderators: phranque

Message Too Old, No Replies

htaccess to allow single IP address

and redirect all other ip's to an external url

         

danbhala

11:01 am on Mar 23, 2007 (gmt 0)

10+ Year Member



Hi, I'm about to launch a website over the next week or so and I'd like to upload the site to the server so i can make the finishing touches and make sure everything runs.

I'd like to only allow my ip address and deny all other addresses from viewing the whole website while i make sure its ok.

also i would like to forward all other ip addresses (except for mine) to an external url.

so far i have the allow/deny permissions

Order Deny,Allow
Allow from 1.2.3.4
Deny from all

all i need now is to forward everyone else, to somewhere else

any help would be greatly appreciated :)

jdMorgan

11:41 am on Mar 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your solution will return a 403-Forbidden response to all but your own IP address.

If instead you want to redirect all other clients, then use mod_rewrite:


Options +FollowSymLinks
RewriteEngine on
#
# Redirect all except developer IP address to alternate domain
RewriteCond %{REMOTE_ADDR} !^1.2\.3\.4$
RewriteRule .* http://www.google.com/ [R=302,L]

The Options line may be required, may not be needed, or it may not be allowed, depending on your current server configuration. I include it for completeness.

Jim

danbhala

12:31 pm on Mar 23, 2007 (gmt 0)

10+ Year Member



you legend!

cheers :)

danbhala

9:25 am on Mar 28, 2007 (gmt 0)

10+ Year Member



if i would like to use add my home and work ip, how woudld i modify this?

Options +FollowSymLinks
RewriteEngine on
#
# Redirect all except developer IP address to alternate domain
RewriteCond %{REMOTE_ADDR}!^1.2\.3\.4$ #home
RewriteCond %{REMOTE_ADDR}!^5.6\.7\.8$ #work
RewriteRule .* [google.com...] [R=302,L]

is the above possible?

jdMorgan

12:35 pm on Mar 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure, just note that all literal periods in patterns should be escaped by preceding them with "\" (you copied my typo in the post above), and that comments are not allowed, except on separate lines.

Options +FollowSymLinks
RewriteEngine on
#
# Redirect all except developer IP addresses to alternate domain
# home IP address
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
# work IP address
RewriteCond %{REMOTE_ADDR} !^5\.6\.7\.8$
RewriteRule .* http://www.google.com/ [R=302,L]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim