Forum Moderators: phranque

Message Too Old, No Replies

Redirect entire site to temporary page

using htaccess

         

chriswragg

10:38 am on Sep 2, 2006 (gmt 0)

10+ Year Member



I have written the following script in an attempt to only allow my ip to access my website should I need to perform any maintenence or testing, however it does not seem to work.

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME}!http://subdomain\.domain\.com/temp/index\.php
RewriteCond %{REMOTE_HOST}!888\.888\.888\.888
RewriteRule ^(.*)/?$ [subdomain\.domain\.com...] [R=301]

888.888.888.888 replaced with my ip address, also a space between the } and! in the condition (it gets removed by the forum)

When I visit the site using my ip, it works fine. However if i change the ip so it would appear as if I were a normal user, I get an unending redirect.

Any help would be appreciated

Thanks

Caterham

5:00 pm on Sep 2, 2006 (gmt 0)

10+ Year Member



SCRIPT_FILENAME does not contain that value. The value depends upon context and is either r->filename (per-dir) or r->uri (per-server).

Or to be more correct: The value is always r->filename, but in per-server context r->filename has in its initial state the value of r->uri.

RewriteEngine on
# there is no need for a regEx here
RewriteCond %{REMOTE_HOST} !=888.888.888.888
# exclude the file directly in your rule-pattern
RewriteRule !^temp/index\.php$ http://subdomain.domain.com/temp/index.php [R=301,L]

[edited by: Caterham at 5:09 pm (utc) on Sep. 2, 2006]

jdMorgan

7:17 pm on Sep 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> # there is no need for a regEx here

Be aware that if a port number is appended to the HTTP_HOST, this match will fail. I recommend using regex without an end anchor, or something like ^1\.1\.1\.1(:[0-9]{1,5})?$ or ^1\.1\.1\.1(:80)?$

Using string matching in RewriteCond is fine, but only when an exact match can be assured.

Jim

Caterham

11:45 pm on Sep 3, 2006 (gmt 0)

10+ Year Member



is appended to the HTTP_HOST
We're matching against REMOTE_HOST here which does not contain any ports but the result of the reverse DNS lookup for REMOTE_ADDR. But anyway if the rev. lookup does not return a hostname, shouldn't REMOTE_HOST be empty at all (instead of copying the value of REMOTE_ADDR)?

So may be OP ment REMOTE_ADDR instead?

jdMorgan

2:26 am on Sep 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I think I posted to the wrong thread, actually... :o

But if you wish to check the requesting client's IP address, REMOTE_ADDR is the correct variable to check. Checking REMOTE_HOST will invoke a reverse DNS lookup, and return a hostname if available, which won't match an IP address. Since an IP address is what we want to test here, the RNDS lookup for REMOTE_HOST won't work and wastes a lot of time.

Jim