How to create a website system maintenance page and redirect


Let’s say we are performing a system maintenance task on the database server but not the web server will not be affected. Given that our websites are database-driven and use this database server, we want to redirect all website visits to a maintenance page during the system maintenance period.

Here are the steps:

  1. Create the site maintenance page
  2. Create a redirect rule using the IIS URL Rewrite
  3. Activate the rule at system maintenance time

Create the site maintenance page

1 Create an HTML page with the following information

  • Page title
  • Brief description of maintenance window
  • Time service resumes

Include the style inline on the page, and save this page as maintenance.html on the website root. Here’s a sample:

2 Creating the IIS URL Rewrite Redirect Rule

Let’s use the IIS Rewrite Module to create a rule to redirect all requests to the website to a maintenance page that we created in the step above:

  • Logon to the IIS Manager
  • Select the site and then URL Rewrite
  • Add Rule(s)…
  • Blank Rule under Inbound Rules
  • Enter the following for this new rule:
    • Name: Site Maintenance
    • Expand the Match URL section and enter or select the following:
      • Requested URL: Matches the pattern
      • Using: Regular Expressions
      • Pattern: (.*)
        We want to match all requests coming to the site, hence (.*)
      • Ensure Ignore case is checked
    • Expand the Conditions section and enter or select the following:
      • Logical Group: Matches All
      • Click Add and add these conditions:
        • Exclude maintenance (we want to show the maintenance.html page)
          • Condition input: {REQUEST_URI}
          • Check if input string matches: Does not match the pattern
          • Pattern: maintenance
        • Exclude images (we want to show the site banner images)
          • Condition input: {REQUEST_URI}
          • Check if input string matches: Does not match the pattern
          • Pattern: images
    • Expand the Actions section and enter or select the following:
      • Action type: Redirect
      • Redirect URL: http://<domain-name>/maintenance.html
        This is the html page named maintenance.html that you created in the step above.
      • Uncheck Append query string
      • Redirect type: Temporary (307)
  • Ensure this rule is the first one for the website (as we do not want to process any other rules if they exist). If not, move it to the top.
  • Test this new rule (preferably on a non-production server first)

3 Activate the rule at system maintenance time

On the day of the system maintenance, activate the rule using these steps:

  • Logon to the IIS Manager
  • Select the site and then URL Rewrite
  • Select the Site Maintenance rule
  • Click Enable Rule under Inbound Rules in the Actions right pane

Once maintenance is done, don’t forget to log back to IIS Manager and disable the Site Maintenance IIS Rewrite rule.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s