I’ve created a .htaccess file to redirect a specific IP address to another file:
# Allow rewriting of htaccess
RewriteEngine On
RewriteBase /
# Get remote address/block of addresses to redirect
RewriteCond %{REMOTE_ADDR} 127\.0\.0\.1
# Define the file being accessed
RewriteCond %{REQUEST_URI} /index\.php$
# When the remote address(es) try to access the file above redirect them to the file below
RewriteRule .* /other-index\.php [R,L]
This works well and the above redirects localhost to other-index.php if it tries to access index.php but allows all other remote hosts to access index.php.
The remote host is calling: http://www.example.com/index.php
My question is can the remote host (in this case localhost) find out that it is being redirected by the server?
Yes because the client (at 127.0.0.1) makes a request for
/index.phpto the server. The server responds with a 302 redirecting the client to a different location/other-index.php.Normally this all happens seemlessly, like if you are using a browser. The browser gets the new location (
/other-index.php) and simply makes a new request to the server for the new location and gets it. It happens instantly. But the remote host (the client) knows it’s being redirected because the first request it made (for/index.php) resulted in a 302 with a new location (/other-index.php).If the
Rflag in the square brackets of yourRewriteRulewas omitted, there wouldn’t be a redirect and the URI would be internally re-written by the server, and the client (the remote host) would be oblivious to the fact that was served the content atother-index.phpwhen it requestedother.php.