Prepping for a Surge

Posted by Spencer on March 16th, 2015

It’s always good to be prepared. So while I don’t imagine my posts going viral anytime soon, I thought it would be a fun thought experiment to figure out what I’d do. An important first step would be serving up a static version of the viral page. Here’s the plan I put together!


If the server is totally crapping out, it may be necessary to stop Apache while making the changes.

$ sudo service apache2 stop

Make sure to do that only after viewing/copying the page source for the viral post- it’s needed later. Okay, now time to get to work. And fast!

$ cd [main blog dir]
$ mkdir static-temp
$ cd static-temp
$ vim [article name].html // i.e. my-viral-post.html
paste in the page source code, save
$ cd ..
$ vim .htaccess
in the WP block, right after "RewriteEngine On", add:
Redirect 302 /2014/09/my-viral-post/ /static-temp/my-viral-post.html

If Apache was stopped, now is the time to restart it.

$ sudo service apache2 start


In the main .htaccess file, comment out the redirect. Next, we want to point anyone who linked to the static version back to the original.

$ vim static-temp/.htaccess, insert:
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /static-temp/my-viral-post.html /2014/09/my-viral-post/

In other words, change the redirect to a 301, and flip the path args from the main redirect.

Also worth considering: minimizing or disabling images, upping Apache thread limits if CPU has plenty of headroom.

Posted in Uncategorized