We're expecting a large spike in traffic to our website this week. If the site becomes overloaded (i.e. visitors are getting a 503 error), I want to redirect visitors to another web address. How would I go about doing this?

  • 1
    Have you load tested your current system? I ask this because I had a single Cobalt 3 server a decade ago with a completely dynamic site that handled 100,000 page requests per hour. That is 2.4 million per day! It was responsive enough and had other sites on the server. Of course the system was not as fast as normal, but it handled the requests rather well. Another example: I managed a website that had just 3 4x200Mhz Xeon CPU w/4gig memory servers that handled as much traffic as Microsoft. You may be in better condition than you think.
    – closetnoc
    Jan 21 '15 at 17:38
  • Is it too late to just spin up an amazon instance and push move your site out there? Is this a web application or just a informational web site? If the latter then it should take a LOT to take down a server as closetnoc noted.
    – NotMe
    Jan 21 '15 at 19:41
  • What server are you running on? IIS? Apache? Jan 23 '15 at 11:17

When your website is too busy due to a large traffic, the best way of redirection is using custom error documents. So, when a user gets 503 error code, the server will redirect visitors to the custom error document page you have defined.

There are different ways for different servers to customize error document pages.

1. For Apache server, add the following code in .htaccess file.

ErrorDocument 503 http://example.com/maintenance.html

2. For IIS 7 server, add the following code in web.config

    <httpErrors errorMode="Custom" existingResponse="Replace">
        <remove statusCode="503" />
        <error statusCode="503" responseMode="Redirect" 
               path="http://example.com/maintenance.htm" />

Ref. CustomError in web.config

3. For Tomcat 7 server, add the following code in WEB-INF/web.xml file.



Ref. Custom Error Page in Tomcat 7

  • I see that you just added code for IIS and Tomcat 7, however only your Apache directive is going to issue a redirect. The others are just ways of showing a custom error page. Jan 21 '15 at 17:46
  • hmm..you got that right. I haven't work on those servers yet. So don't know the best way. So, I tried to complete my answer with the best I could do. Jan 21 '15 at 17:53
  • 1
    For IIS you can change the responseMode from File to Redirect and then specify an absolute URL which will allow you to send the requests to a different server. Jan 27 '15 at 16:39

It seems like you're aiming for the second-worst outcome. If you're expecting a spike, you have time to do something:

  • Implement in-code caching (can be easy, can take a while to get right)
  • Optimise static files (jpegoptim, optipng, more-css, etc) to reduce bandwidth, speed things up for all users.
  • Move your static stuff to a CDN to remove those requests from your network completely.
  • If it's all static, copy the site to a few more computers and use a load balancer to keep the site up under one IP. Sounds expensive but many VPS providers will give you a setup like that for about $20 a week.
  • Or look at CloudFlare (et al) front-end caching services. Even a novice can implement these in minutes but it won't help much alone if you have a highly dynamic site.

Just get things ready so that you know that if things break down, you've done everything to make sure those users get what they wanted the first time around. Planning to fail isn't a bad practice but look at the options to avoid failing in the first place!

But yes, the best standard option (which you should have implemented already) is to customise your error pages so that people know something wrong is going on. I should point out that most people react very negatively to these. If the message is "please come back later" expect only a fraction of a fraction to return.

So again, this is an ideal opportunity to revisit how the site is hosted and if nothing else have a [practised] plan to swap over to better hardware within an hour of failure.


There are things you can do at a number of levels:

Network Level

  1. Network Hardware: Install a load-balancer, with addition servers behind it. This will allow you to run your existing set-up fairly easily, but will probably cost quite a lot of money to setup in the time frame you have (depending on your hosting providers support levels)

  2. Virtual Hardware: Move to a cloud based system with load-balancing built in. This will give you the benefits of option 1, without the potentially hefty setup costs with your hosts (you only pay for what you use), however this may take time on your side to set up.

These are probably the "best" options for dealing with this, and are very tried and trusted, but they do come at a financial cost - especially for point 1.

However, they can both be configured to handle your "worst case" scenario of "Our servers can't cope" - the loadbalancers can be configured to route all traffic to a server that just holds a flat page saying the site is currently down, but here's a bit of information.

Software Level

In addition to the methods laid out in the other answers, most servers allow you to set up error pages in a number of ways - typically these are a page on the site, however you should also be able to issue a redirect to a page on a different server as well.

In IIS for example you can create an error response that "Responds with a 302 redirect" - this can be a URL on a completely different server - you can do this at the .net error page level or the IIS error level:


<customErrors mode="RemoteOnly">
  <remove statusCode="503" />
  <error redirect="htp://www.example.com/sitedown.html" statusCode="503" />


Setting a redirect error in IIS


If you are using apache: Search your root folder for the file named "htaccess.txt" or ".htaccess". Add the following line:

ErrorDocument 503 http://www.example.com/customhtml.html

You have your visitors redirected to customhtml.html. You can add an iframe of your "another web address" in the HTML code.

  • 1
    I don't think this is substantially different from Nikhil Supekar's answer. Jan 21 '15 at 17:44

I will suggest to go for multi servers to solve this issue , where servers are connected in clustred format . So in case server load of one goes high your traffic is diverted to second server and so on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.