The Blog

Serve landing page while building a new wordpress site

05 Apr 12

If you’re a web developer you confronted by this at least once. If you don’t own a development webserver you’ll need to make your developments in the production webserver. This means that everyone could see your work-in-progress easily.

A common pattern is to create an index.html file ( which gets served – almost ever – before index.php ) which will contain a specific landing page with an “under construction” text.

How to serve the index.html file to “regular people” while you work on wordpress ( index.php ) ?

It’s quite easy using .htaccess and mod_rewrite of apache. The basic concepts are:

  • WordPress logged in people will see the “work in progress” website
  • Not logged in people will see the “site under construction” page

In order to achieve that, you’ve to prepend the following lines to your .htaccess file  ( placed in your document root ) :

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} index.html$
  RewriteCond %{HTTP_COOKIE} ^.*wordpress_logged_in.*$ [NC]
  RewriteRule . /index.php [L]
</IfModule>

As you can see we only override the normal web-flow only if the browser is going to request the index.html file and the user has the wordpress_logged_in cookie setted.

Whenever you need to see your “real website” you just need to point your browser to http://example.com/wp-admin , login and then you’ll be able to see the website you’re creating and not the “under construction” page.

Note: This is only a partial solution and people could be smart enough to emulate the wordpress_logged_in cookie and see your work in progress anyway. In my case-scenarios this was more than enough.