Maintenance page
Serve a custom maintenance page. Ideal for downtime notifications, planned maintenance, or emergency messages.
Last updated Oct 13, 2025
Snippet code
// Define your customizable inputs
const statusCode = 503;
const title = "We'll Be Right Back!";
const message =
"Our site is currently undergoing scheduled maintenance. We’re working hard to bring you a better experience. Thank you for your patience and understanding.";
const estimatedTime = "1 hour";
const contactEmail = "support@example.com";
const contactPhone = "+1 234 567 89";
export default {
async fetch(request) {
// Serve the maintenance page as a response
return new Response(generateMaintenancePage(), {
status: statusCode,
headers: {
"Content-Type": "text/html",
"Retry-After": "3600", // Suggest retry after 1 hour
},
});
},
};
function generateMaintenancePage() {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${title}</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f4f4f4;
color: #333;
text-align: center;
}
.container {
max-width: 600px;
padding: 20px;
}
h1 {
font-size: 2rem;
color: #0056b3;
margin-bottom: 10px;
}
p {
font-size: 1rem;
margin-bottom: 20px;
line-height: 1.5;
}
.contact {
margin-top: 20px;
font-size: 0.9rem;
color: #666;
}
.contact a {
color: #0056b3;
text-decoration: none;
}
.contact a:hover {
text-decoration: underline;
}
.logo {
margin: 20px 0;
max-width: 150px;
}
.timer {
font-weight: bold;
color: #e63946;
}
</style>
</head>
<body>
<div class="container">
<h1>${title}</h1>
<p>${message}</p>
<p>If all goes to plan, we'll be back online in <span class="timer">${estimatedTime}</span>. 🚀</p>
<p class="contact">
Need help? Reach out to us at <a href="mailto:${contactEmail}">${contactEmail}</a>
or call us at <a href="tel:${contactPhone}">${contactPhone}</a>.
</p>
</div>
</body>
</html>
`;
}
Snippet rule
Configure a custom filter expression:
| Field | Operator | Value |
|---|---|---|
| IP Source Address | is not in list | admin_ips |
If you are using the Expression Editor, enter the following expression:
(not ip.src in $admin_ips)
The IP list admin_ips was previously created and contains the list of IP addresses of the site administrators, which will be able to access the site during the maintenance period.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/rules/snippets/examples/maintenance/#page","headline":"Maintenance page","description":"Serve a custom maintenance page instead of fetching content from the origin server or cache. Ideal for downtime notifications, planned maintenance, or emergency messages.","url":"https://developers.cloudflare.com/rules/snippets/examples/maintenance/","inLanguage":"en","image":"https://developers.cloudflare.com/rules/snippets/examples/maintenance/og.png?v=80032e7fbb11539a","dateModified":"2025-10-13","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["Redirects"]}
description: Get a specific Set-Cookie header and update it with a certain value.
title: Override a Set-Cookie header with a certain value
image: https://developers.cloudflare.com/rules/snippets/examples/override-set-cookies-value/og.png?v=c31753ddec97cacf
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/rules/llms.txt
Use this file to discover all available pages before exploring further.
Docs