homepage Welcome to WebmasterWorld Guest from 23.22.173.58
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess-redirect all but my IP
geoffb

5+ Year Member



 
Msg#: 4450754 posted 10:39 am on May 8, 2012 (gmt 0)

Hi,

I have a directory name /development which I dont want my client to see whilst I develop a wp cms site.

I have a holding page at the root in an index.html filename and would like to redirect anyone except my IP to the root holding page.

Any help really appreciated.

Thanks
geoffb

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4450754 posted 11:13 am on May 8, 2012 (gmt 0)

It's two (perhaps three) lines of code, using a RewriteCond (or two) and a RewriteRule.

What have you tried so far?

geoffb

5+ Year Member



 
Msg#: 4450754 posted 11:41 am on May 8, 2012 (gmt 0)

Hi g1smd

I have tried:

RewriteEngine on
RewriteCond $1 !^http://www.mysite.com/development
RewriteCond %{REMOTE_HOST} !^00\.00\.00\.00
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

[edited by: incrediBILL at 12:35 pm (utc) on May 8, 2012]
[edit reason] fixed URL w/example.com [/edit]

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4450754 posted 12:11 pm on May 8, 2012 (gmt 0)

$1 will never contain protocol or hostname nor slash after hostname.

Use example.com in code snippets in this forum.

I thought you wanted to redirect to a specific page? Your code doesn't do that.

You should check (with a RewriteCond) that the user is not requesting the redirected-to page otherwise (.*) will match again and create an infinite redirect loop.

You should serve "503 Unavailable" to Google and others until you're ready to go.

geoffb

5+ Year Member



 
Msg#: 4450754 posted 12:27 pm on May 8, 2012 (gmt 0)

Hi,

So would this not work:

RewriteEngine on
RewriteCond $1 !^development
RewriteCond %{REMOTE_HOST} !^00\.00\.00\.00
RewriteRule (.*) http://www.example.com/index.html/$1 [R=301,L]

Thanks

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4450754 posted 12:50 pm on May 8, 2012 (gmt 0)

Use the Live HTTP Headers extension for Firefox to test it.

You'll likely see an infinite loop with the target URL getting longer and longer.

This is also one of those rare cases where a 302 redirect might be in order.

geoffb

5+ Year Member



 
Msg#: 4450754 posted 1:01 pm on May 8, 2012 (gmt 0)

Hi g1smd,

Thanks, I sorted it with a 302 redirect like you said.

I only want it as nearing completion i clicked on a link I built in the footer and went to the client site, this development domain link will now show on the clients Google Analytics so i just wanted to send anything back than the website for them if they see my link and go to have a look. Now only my IP serves up the site while I finish off.

thanks for the tip.

geoffb

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4450754 posted 2:02 pm on May 8, 2012 (gmt 0)

What do other users see?

Have you tested it to be sure?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved