Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

334
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda