Search code examples
.htaccess

Redirect all users except me during maintenance


I have this very simple rule in my .htaccess. Basically, i want to redirect all users except me during maintenance. For some reason, it is also redirecting me to maintenance.php.

I don't have any other .htaccess.

The .htaccess is found on My document root: /Users/myname/Sites

# redirect to maintenance page
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteCond %{REQUEST_URI} !/maintenance.php$ [NC]
RewriteRule ^(.*)$ /maintenance.php [R=302,L]

I've search and search here and tried pretty much everything for the last 3 days with no success. I cant find what it's wrong with this very simple piece of code? Anyone has any ideas?

If it helps, my access_log says something like:

::1 - - [07/Mar/2021:13:47:36 -0500] "GET /maintenance.php HTTP/1.1" 200 2956

Solution

  • You are redirected your self on /meintanence.php as logfile indicates. Please test this to avoid local request redirecting:

    # redirect to maintenance page
    RewriteCond %{REMOTE_ADDR} !^::1
    RewriteCond %{REQUEST_URI} !/maintenance.php$ [NC]
    RewriteRule ^(.*)$ /maintenance.php [R=302,L]
    

    ::1 is the loopback address in IPv6, as the IPv4 version is 127.0.0.1.