Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

336
Vistas
Apache rewrite rules for maintenance, htaccess not allowing my IP address through

I'm working on a template to use for site maintenance. Took a while to figure out that Apache wanted absolute paths, but now everything is working, short of the IP.

I'm trying to allow my IP and the IP of the server (domain) when maintenance is activated, so the maintenance page will only be served to guests. However, I'm also getting served the maintenance page. I suck at regex, so it might be a simple error.

Here are my Apache directives.

## Maintenance
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    # local ip
    RewriteCond %{REMOTE_ADDR} !^111\.111\.33\.44
    # server ip
    RewriteCond %{REMOTE_ADDR} !^222\.222\.333\.444
    # maintenance folder
    RewriteCond %{REQUEST_URI} ^/maintenance/
    RewriteRule .+ - [L]
    # maintenance files
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|woff|woff2|eot|ttf|svg) [NC]
    RewriteCond %{REQUEST_URI} !^/maintenance/maintenance\.html$
    RewriteRule ^(.*) https://example.com/maintenance/maintenance.html [R=307,L]
</IfModule>

ErrorDocument 503 /maintenance/maintenance.html
ErrorDocument 307 /maintenance/maintenance.html

<IfModule mod_headers.c>
    #do not cache
    Header Set Cache-Control "max-age=0, no-store"
</IfModule>
## End Maintenance

# Force HTTPS
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I managed to figure this out, so in case anyone else who's as bad at regex as I am comes across this, it may help them.

I had two unneeded lines of directives and the ^ was unnecessary or causing problems. $ after IP is to make sure a similar longer IP can't get through. I also switched to a 302 error since it is a temporary redirect for maintenance.

Make sure your folder and html file path is set correctly and uses absolute paths. If you aren't using a folder, the path directly to the html should work. I used a folder because I have images and fonts also loading and like to keep things tidy.

<IfModule mod_rewrite.c>
    RewriteEngine On
    # local ip
    RewriteCond %{REMOTE_HOST} !^111\.111\.22\.33$
    # server ip
    RewriteCond %{REMOTE_ADDR} !^222\.222\.333\.444$
    # maintenance folder
    RewriteCond %{REQUEST_URI} !^/maintenance/(.)*$
    # maintenance files
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|woff|woff2|eot|ttf|svg) [NC]
    RewriteCond %{REQUEST_URI} !/maintenance/maintenance\.html$ [NC]
    RewriteRule .* /maintenance/maintenance.html [R=302,L]
</IfModule>

<IfModule mod_headers.c>
    #do not cache
    Header Set Cache-Control "max-age=0, no-store"
</IfModule>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda