Drupal Homepage Takeover

I had a recent requirement where I needed to temporarily replace the homepage of a website running Drupal with a simple HTML page. I wanted to do this without doing lots of changes to the site templates so I needed a solution that was easy to turn on and off and would still retain the Drupal site as it was. I found the simplest solution was to add a rule to the DirectoryIndex rule in the sites .htaccess file. Here is the rule I used.

# Set the default handler.
DirectoryIndex newhomepage.html index.php index.html index.htm

With this in place I just needed to create a file called newhomepage.html in the root directory for this to be used instead of the main index.php file. When the user visits any other page on the Drupal site then the index.php file is used as it normally is. The good thing about this method is that it can be turned off easily by just removing the newhomepage.html file.

One thing to note is that if you have the Global Redirect module installed then make sure you untick the option to redirect the home page away from /home otherwise your users will not be able to see the normal home page.

There is a small risk with this in that if a file of the same name is found in a directory then it will be used instead of the main index.php file. This risk can be overcome by naming the file in a unique way but if you have people creating directory index files on your server then you might have bigger problems.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
1 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.