Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

333
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!