Forum Moderators: phranque

Message Too Old, No Replies

How to exclude my IP from redirect to a subdirectory

         

james11

7:21 pm on Sep 17, 2012 (gmt 0)

10+ Year Member



Hi everyone!

I am trying to make some updates to my site. My current site.com redirects to site.com/main. I would like to keep the redirect to the 'main' subdirectory for everyone except me.

I've read a similar topic [webmasterworld.com ] on this forum, however the .htaccess code didn't work.

Here is my current .htaccess:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{REQUEST_URI} !^/main/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /main/$1

RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteRule ^(/)?$ main/ [L]


I've tried
RewriteCond %{REMOTE_HOST} !^64\.46\.0\.106$
but it didn't work.

g1smd

8:07 pm on Sep 17, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Depends where you put it, as you have two rules.

Additionally, you don't have any redirects. Both of your rules are internal rewrites.

You should also be escaping literal periods in patterns.

james11

9:24 pm on Sep 17, 2012 (gmt 0)

10+ Year Member



The code was something I had found on various forums. How would the code look like if you were doing it with your method? site.com redirects to site.com/main (except ip ip.ip.ip.ip

[edited by: engine at 7:33 am (utc) on Sep 18, 2012]
[edit reason] ip [/edit]

phranque

9:55 pm on Sep 17, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, james11!

but it didn't work.

what was your request and what was the server's response?

james11

10:12 pm on Sep 17, 2012 (gmt 0)

10+ Year Member



thanks! well, once I added "RewriteCond %{REMOTE_HOST} !^00\.00\.0\.000$" to the original code, the redirect stopped working for everyone.

[edited by: engine at 9:33 am (utc) on Sep 19, 2012]
[edit reason] ip obfuscated [/edit]

lucy24

11:36 pm on Sep 17, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule ^(.*)$ /main/$1

RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteRule ^(/)?$ main/ [L]


You seem to be missing one [L] flag and two [R=301]. Where did you add the condition excluding yourself? You've got two Rules.

james11

11:41 pm on Sep 17, 2012 (gmt 0)

10+ Year Member



Right below the

RewriteRule ^(/)?$ main/ [L]

phranque

4:25 am on Sep 18, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



redirect stopped working for everyone

what url did you request?
(use example.com for your domain so it doesn't link)

what status code and response did you get for that request?