Check 05.15 · HTTP and redirects

Use 503 during temporary maintenance

Serve a 503 with Retry-After during maintenance on Apache, Nginx, Cloudflare, AWS, WordPress, PrestaShop, Magento, Laravel or Next.js, without blocking robots.txt.

Priority
Critical
Difficulty
Intermediate
Estimated time
30 min to 1 h
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

During a short maintenance window, the site must respond with 503 Service Unavailable and a Retry-After header, not an “under construction” page served with 200, a redirect or a 404. The 503 tells crawlers that the downtime is temporary: they come back later without touching the index. Once this is done, you have a ready-to-use maintenance mode that returns 503 to everyone except your team, keeps robots.txt accessible, and can be switched off with a single command.

Why it matters

Google recommends the 503 for planned downtime. A 404 would suggest that the pages have disappeared; a maintenance page served with 200 would, from the crawler's point of view, replace the content of every URL with the same message, with a risk of soft 404s or of that message being indexed.

Google's documentation also sets the limits:

  • Short duration: the 503 is meant for a few hours, one or two days at most. If Googlebot receives these codes on the same URL for several days, the URL may drop out of the index.
  • The whole hostname: 503s slow down crawling of the entire site until responses return to normal.
  • No updates: during a 503, Google cannot refresh titles, descriptions or structured data.
  • robots.txt is separate: a robots.txt that returns 503 blocks all crawling. Google asks you to keep it accessible.
  • Retry-After: a value in seconds or a date in HTTP format, which Google's crawlers may use to know when to come back.

Generative engines that retrieve the page during maintenance get an error and rely on another source; nothing lasting if the maintenance is short.

Warning: beyond two days, the 503 is no longer appropriate. For a long closure, Google recommends keeping the site online with reduced functionality (ordering disabled, an information banner), or an indexable homepage served with 200 that explains the situation.

What it improves

  • Indexing Pages stay in the index during a maintenance window of a few hours.
  • Crawling Crawlers come back after the maintenance instead of recording permanent errors.
  • Snippets No “Maintenance in progress” page indexed in place of your content.
  • Visitors A clear message with the time the site will be back, rather than a broken page or a technical error.
  • Safer updates Nobody places an order or writes to the database during a migration.

How to check

During maintenance, or on staging in maintenance mode:

curl -s -o /dev/null -D - https://example.com/ | grep -i -E "^HTTP|retry-after|cache-control"
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/robots.txt
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/une-page-profonde/

Compliant result:

HTTP/2 503
retry-after: 3600
cache-control: no-store
200
503

The homepage and deep pages return 503 with Retry-After, and robots.txt returns 200. Outside maintenance, check the opposite: everything is back to 200, and no cache is still serving the maintenance page.

Afterwards, the Crawl stats in Search Console show the 503s over the period; they must stop abruptly at the end of the maintenance.

How to implement

Before you start

Prepare three things, valid for every environment:

  1. A self-contained maintenance page (maintenance.html): inline styles, no external image or stylesheet to load, since those files would also receive a 503. State the reason and the expected time the site will be back.
  2. The exceptions: robots.txt, the team's IP addresses and, if needed, a health route for the load balancer.
  3. A realistic duration for Retry-After: the expected duration in seconds (3600 for one hour).

Schedule the maintenance during your audience's off-peak hours, test maintenance mode on staging, and record the start and end in the incident log (opens in a new tab). If the maintenance runs over by more than a day, reassess: put the site back online in reduced mode rather than prolonging the 503.

Apache

Versions Apache 2.4.10 and later.

Place this block at the top of the .htaccess file or in the virtual host, before the CMS rules. Maintenance is switched on by creating a maintenance.flag file at the site root:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT}/maintenance.flag -f
    RewriteCond %{REMOTE_ADDR} !^203\.0\.113\.10$
    RewriteCond %{REQUEST_URI} !^/(robots\.txt|maintenance\.html)$
    RewriteRule ^ - [R=503,L]
</IfModule>

ErrorDocument 503 /maintenance.html

<IfModule mod_headers.c>
    Header always set Retry-After "3600" "expr=%{REQUEST_STATUS} == 503"
    Header always set Cache-Control "no-store" "expr=%{REQUEST_STATUS} == 503"
</IfModule>

With [R=503], Apache drops the rewrite and returns the 503 code with the page declared by ErrorDocument. Behind Cloudflare or another proxy, REMOTE_ADDR contains the proxy's address: enable mod_remoteip, or test the CF-Connecting-IP header with RewriteCond %{HTTP:CF-Connecting-IP}.

touch /var/www/example/maintenance.flag   # start
rm /var/www/example/maintenance.flag      # end

Nginx

Versions Nginx 1.18 and later.

In the http context, list the allowed addresses:

geo $equipe {
    default 0;
    203.0.113.10 1;
}

In the server block:

set $maintenance 0;

if (-f /var/www/example/maintenance.flag) {
    set $maintenance 1;
}

if ($equipe) {
    set $maintenance 0;
}

if ($uri ~ ^/(robots\.txt|maintenance\.html)$) {
    set $maintenance 0;
}

if ($maintenance) {
    return 503;
}

error_page 503 /maintenance.html;

location = /maintenance.html {
    root /var/www/maintenance;
    internal;
    add_header Retry-After 3600 always;
    add_header Cache-Control "no-store" always;
}

The exception for /maintenance.html prevents the error page from triggering a 503 itself. The always parameter is required: without it, add_header does not apply to 503 responses. Reload once with sudo nginx -t && sudo systemctl reload nginx; after that, the presence of the file is enough.

IIS

Versions IIS 10, URL Rewrite module 2.1; ASP.NET Core Module for app_offline.htm.

For an ASP.NET Core application, placing an app_offline.htm file at the site root stops the application and serves that file with a 503 code. For another site, use a URL Rewrite module rule in web.config:

<rewrite>
  <rules>
    <rule name="Maintenance" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{REMOTE_ADDR}" pattern="^203\.0\.113\.10$" negate="true" />
        <add input="{URL}" pattern="^/robots\.txt$" negate="true" />
      </conditions>
      <action type="CustomResponse" statusCode="503" statusReason="Service Unavailable" statusDescription="Maintenance in progress" />
    </rule>
  </rules>
</rewrite>

Cloudflare

Versions Cloudflare Workers, all plans (including Workers Free), November 2026.

A Worker displays the maintenance page at the edge, even if the origin is down. Create it in the account's Workers & Pages section, then attach the example.com/* route to it in its Domains & Routes settings:

const IP_EQUIPE = ['203.0.113.10'];

const PAGE = `<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Maintenance in progress</title>
<body style="font-family: sans-serif; max-width: 40em; margin: 4em auto; padding: 0 1em">
<h1>Maintenance in progress</h1>
<p>The site will be back around 7 a.m. (Paris time). Thank you for your patience.</p>
</body>
</html>`;

export default {
  async fetch(request) {
    const url = new URL(request.url);
    const ip = request.headers.get('CF-Connecting-IP');

    if (url.pathname === '/robots.txt' || IP_EQUIPE.includes(ip)) {
      return fetch(request);
    }

    return new Response(PAGE, {
      status: 503,
      headers: {
        'Content-Type': 'text/html; charset=utf-8',
        'Retry-After': '3600',
        'Cache-Control': 'no-store',
      },
    });
  },
};

To end the maintenance, remove the route or disable the Worker. Cloudflare does not cache 503 responses by default. During maintenance at the origin without a Worker, the origin itself must return 503: Cloudflare passes that code on as is.

AWS

Versions Elastic Load Balancing (ALB) and CloudFront, AWS CLI v2, November 2026.

Application Load Balancer: add a rule at the top of the listener with a fixed response action, code 503, type text/html. The body is limited to 1,024 characters and the action does not let you add headers, so no Retry-After. Add a higher-priority rule that lets /robots.txt through to the target group, if the application stays online for that file.

aws elbv2 create-rule --listener-arn ARN_DE_L_ECOUTEUR --priority 1 \
  --conditions '[{"Field":"path-pattern","PathPatternConfig":{"Values":["/*"]}}]' \
  --actions '[{"Type":"fixed-response","FixedResponseConfig":{"StatusCode":"503","ContentType":"text/html","MessageBody":"<h1>Maintenance in progress</h1><p>Back around 7 a.m.</p>"}}]'

Delete the rule at the end (aws elbv2 delete-rule --rule-arn …). CloudFront caches 503s from the origin for 10 seconds by default: keep this value short so that the site comes back as soon as the maintenance ends.

Plesk

Versions Plesk Obsidian 18.0.

For an Apache site, use the block from the Apache section in the .htaccess file. In Nginx-only mode, paste the server block from the Nginx section (except the geo block, replaced by an if ($remote_addr = 203.0.113.10) condition) into Websites & Domains > Apache & nginx Settings > Additional nginx directives. For WordPress, WP Toolkit's maintenance mode is another option: check the code it returns with curl.

cPanel

Versions cPanel & WHM 110 and later, Jupiter theme.

Paste the block from the Apache section at the top of public_html/.htaccess with the File Manager, and place maintenance.html in public_html. The maintenance.flag file, created or deleted from the File Manager, switches maintenance on and off.

Shared hosting

The .htaccess method from the Apache section works with most shared hosts. Some offer a maintenance switch in their customer area: test with curl that it really returns 503 and not a page with 200, and that it lets robots.txt through.

WordPress

Versions WordPress 6.4 to 7.1, WP-CLI 2.2 and later.

Built-in mode. During an update, WordPress creates a .maintenance file at the root and returns 503 with Retry-After: 600, for ten minutes at most. For longer maintenance, WP-CLI switches it on and off on demand:

wp maintenance-mode activate
wp maintenance-mode status
wp maintenance-mode deactivate

This mode also blocks the admin. Customize the message with a wp-content/maintenance.php file, served with the 503 code.

Maintenance plugins. Many distinguish a “maintenance” mode (503) from a “coming soon” mode (200, intended for sites that have not launched yet). Choose maintenance mode, then check with curl the code, the Retry-After header and access to robots.txt. Clear the page cache and the CDN cache when switching it on and off, otherwise visitors will see the maintenance page after it ends, or the site during it.

Shopify

Versions Shopify admin, all plans, November 2026.

Shopify does not offer a 503 maintenance mode. Store password protection is meant for launch, not for maintaining a live store: it hides the entire catalog. For a theme redesign, duplicate the theme, work on the unpublished copy, preview it, then publish it: the store stays online. The infrastructure itself is managed by Shopify.

PrestaShop

Versions PrestaShop 8 and 9.

Shop Parameters > General > Maintenance: disable the store, add your IP address to the maintenance IP list and write the message. Check with curl that the page returns 503 for an address that is not allowed.

Magento

Versions Magento Open Source and Adobe Commerce 2.4.6 to 2.4.9.

bin/magento maintenance:enable --ip=203.0.113.10
bin/magento maintenance:status
bin/magento maintenance:disable

Magento then returns 503 to visitors whose address is not allowed. The page displayed is customized in pub/errors/.

Drupal

Versions Drupal 10 and 11, Drush 12 and 13.

Turn on maintenance in Configuration > Development > Maintenance mode, or with Drush:

drush maint:set 1
drush cache:rebuild
drush maint:set 0

drush maint:status shows the status. Before Drush 11.5, the equivalent command is drush state:set system.maintenance_mode 1 --input-format=integer.

Anonymous visitors receive a 503; users with the permission to use the site in maintenance mode browse normally.

Laravel

Versions Laravel 10 to 13.

php artisan down --retry=3600 --secret="jeton-equipe-2026" --render="errors::503"
php artisan up

Laravel returns 503 to every request that goes through the application, with Retry-After thanks to --retry. The team accesses the site by visiting https://example.com/jeton-equipe-2026, which sets a bypass cookie. --render pre-renders the page before the dependencies are loaded, which avoids errors during a Composer update. The robots.txt file in public/ is served directly by the web server: it stays accessible. On several servers, use the cache-based maintenance driver to switch maintenance on everywhere with one command: APP_MAINTENANCE_DRIVER=cache and APP_MAINTENANCE_STORE=redis (or another store shared by the servers) in .env from Laravel 11 onward, or 'maintenance' => ['driver' => 'cache', 'store' => 'redis'] in config/app.php on Laravel 10.

Next.js

Versions Next.js 13.1 to 16.

In proxy.ts from Next.js 16 onward, or in middleware.ts up to Next.js 15, switched on by an environment variable. The default export is accepted by both conventions: the same code works in both files.

import { NextResponse, type NextRequest } from 'next/server';

export default function maintenance(request: NextRequest) {
  if (process.env.MAINTENANCE_MODE !== '1') {
    return NextResponse.next();
  }

  return new NextResponse(
    '<!doctype html><html lang="en"><meta charset="utf-8"><title>Maintenance in progress</title><h1>Maintenance in progress</h1><p>Back around 7 a.m.</p></html>',
    {
      status: 503,
      headers: {
        'Content-Type': 'text/html; charset=utf-8',
        'Retry-After': '3600',
        'Cache-Control': 'no-store',
      },
    },
  );
}

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico|robots.txt).*)'],
};

The matcher excludes robots.txt. Next.js 16 runs proxy.ts on the Node.js runtime; middleware.ts is still accepted but deprecated, and npx @next/codemod@canary middleware-to-proxy . handles the migration. A changed environment variable usually requires a restart or a redeployment; on Vercel, Edge Config lets you switch without redeploying.

Common mistakes

  • “Under construction” page with 200: every URL appears to have the same message as its content, with a risk of soft 404s or of the message being indexed.
  • Redirect to /maintenance: crawlers follow the redirect and see a page with 200.
  • robots.txt returning 503: Google stops crawling the whole site.
  • Maintenance lasting several days: URLs may drop out of the index; switch to a degraded mode.
  • Forgetting always in Nginx: Retry-After is not sent with the 503.
  • Maintenance page loading external files: they return 503 and the page displays without styles.
  • A cache keeping the maintenance page: send Cache-Control: no-store and purge at the end.
  • Forgetting to switch it off: schedule the end or add it to the deployment checklist.

Frequently asked questions

Which HTTP status code should I use during site maintenance?

Use the 503 Service Unavailable code, together with a Retry-After header that indicates the expected duration. Google recommends this code for temporary unavailability: its crawlers come back later without removing the pages from the index. Avoid a maintenance page served with 200, a redirect or a 404. Keep the robots.txt file accessible with 200 throughout the maintenance.

How long can a site stay on 503 without losing its rankings?

Google presents the 503 as a solution for a few hours, one or two days at most. Beyond that, if Googlebot receives this code on the same URLs for several days, they may drop out of its index, and recovering after reindexing can take a long time. For a longer closure, keep the site online with reduced functionality or an indexable homepage that explains the situation.

Should robots.txt return 503 during maintenance?

No. A robots.txt returning a 5xx error leads Google to stop crawling the whole site for at least twelve hours, and its documentation on pausing a site asks you to keep robots.txt accessible. Explicitly exclude it from the maintenance rule, then check with curl that it responds with 200 while the other pages return 503.

Do WordPress maintenance plugins return a 503 code?

WordPress's built-in maintenance mode returns a 503 with a Retry-After header. Plugins vary: many offer a maintenance mode with 503 and a “coming soon” mode with 200, intended for sites that have not launched yet. Always check with curl the code actually returned, the presence of Retry-After and access to robots.txt, after clearing the caches.

Updated on

Topic checklist (PDF)

And now?

In the “HTTP and redirects” topic

  1. Check that active pages return 200
  2. Use 301/308 for permanent moves
  3. Use 302/307 for temporary moves
  4. Fix redirect chains
  5. Fix redirect loops
  6. Fix broken internal links
  7. Fix broken external links
  8. Create a helpful 404 page
  9. Return 404/410 for removed content with no equivalent
  10. Avoid redirecting all removed pages to the homepage
  11. Fix unjustified 403s
  12. Fix excessive 429s
  13. Fix 5xx errors
  14. Monitor server errors
  15. Use 503 during temporary maintenance