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

Apache Web Server Forum

.htaccess redirect
Redirect everyone but me...

 8:34 pm on Aug 14, 2008 (gmt 0)


I have a .htaccess question.

I currently have 2 sites exactly the same name but one has hyphons in the URL and one doesn't and I'm going to move one to the other.

The pages will be exactly the same on both sites.

While I develop the new one, I need to redirect anyone who goes to the NEW site back to the old one - expect me. I know this sounds the wrong way around, but I have links pointing to the new site, which are currently redirected to my old one.

I have this in my NEW site htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) [my-old-site.co.uk...] [R=301,L]

This works great - any page someone goes to on my new site, gets sent to the existing page equivalent on the old site.

Question is - what do I need to add to this to allow MY IP to remain on the new site while I work on it?




 8:51 pm on Aug 14, 2008 (gmt 0)

Something like:

RewriteCond %{REMOTE_IP} !^12\.34\.56\.78

Redirect if not me.


 9:20 pm on Aug 14, 2008 (gmt 0)

The variable should be %{REMOTE_ADDR}, as in:

RewriteCond %{REMOTE_ADDR} !^12\.34\.56\.78$



 9:27 pm on Aug 14, 2008 (gmt 0)

Ooops. Apologies. I knew it wasn't REMOTE_HOST but still messed up.


 10:33 pm on Aug 14, 2008 (gmt 0)

Thanks for the answers,

I am not good at all when it comes to .htaccess - is this all I need to put in the .htaccess file? or does it need to go with other lines?

If that is all I need, can I put it anywhere?

Thanks again!



 10:41 pm on Aug 14, 2008 (gmt 0)

Add the RewriteCond to your existing RewriteRule. Please read the mod_rewrite documentation [httpd.apache.org] at apache.org (and the URL Rewriting Guide linked from that document) if you intend to use mod_rewrite -- It is a compact, powerful, and possibly-dangerous module -- You can easily take your server off-line or ruin your search engine rankings with a single typo or an unforeseen side-effect.

Our goal here is to help you learn how to write your code, but not to write it for you, so please look at the docs.


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