Issue
There may be times when you want to serve a "Coming soon" page or some other small amount of content from inside your Drupal docroot. Situations can include running a separate lightweight landing page, or a flat HTML/CSS/JavaScript brochureware website.
Resolution
You have a few options to serve a static HTML microsite from your Drupal docroot, including either as part of the code repository where you manage them using a version control system (such as Git) or in the files directory where you manage them using sFTP or rsync. In general, you should have only a small set of pages that have minimal impact.
Make uploaded files appear as a docroot subdirectory
To serve a static HTML website in a subdirectory of a domain (such as example.com/static
), you can commit / push an additional directory containing your HTML, CSS, JavaScript, and image files into your code repository.
Alternatively, you can manage your files using a tool, such as sFTP or rsync, to copy the static files into your sites/*/files
directory and redirect requests for a simple path to reference those files instead. This allows you to keep your repository free of changes to non-Drupal files and may make it easier for non-developers to update files, such as images.
In your .htaccess
file, you can use the following code pattern, which you will need to deploy using your Drupal Git repository, in your rewrite rules section (generally between the and tags):
# any paths beginning with the path /static/ (not case sensitive)...
RewriteCond %{REQUEST_URI} ^/static/ [NC]
# Pass-through the matching file from beneath /sites/default/files/SOME-FOLDER and stop processing
RewriteRule ^static/(.*)$ /sites/default/files/folder-with-static-content/$1 [PT,L]
Make sure you place your custom changes directly before the following code snippet in your .htaccess
file; otherwise, the changes will come too late in the file:
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
Run the site on a separate domain
If you need to have pages on domain-b.com
until a new Drupal website or multisite is ready, while continuing to operate your Drupal website on domain-a.com
, you can achieve this by uploading the static website files, and then adding the following code to your docroot/.htaccess
file:
# Only serve the static site for a particular host.
RewriteCond %{HTTP_HOST} ^domain-b\.com$
# Don't loop anything targeting the actual mask directory, to allow
# for linked scripts, stylesheets etc in the static HTML
RewriteCond %{REQUEST_URI} !^/static/
#Any requests that made it this far are served from the /static/ directory
RewriteRule ^(.*)$ /static/$1 [PT]
Combining the two methods
You can combine these two methods to direct a domain to a static HTML website contained in the file system instead of in the code repository. This is particularly useful either if you have a team that needs to be able to update HTML files and is only familiar with sFTP, or if the static website includes large files.
RewriteCond %{HTTP_HOST} ^domain-b\.com$
# Don't loop anything targeting the actual mask directory, to allow
# for linked scripts, stylesheets etc in the static HTML
RewriteCond %{REQUEST_URI} !^/sites/default/files/static/
# pass-through the matching file from beneath /sites/default/files/ and stop processing
RewriteRule ^(.*)$ /sites/default/files/static/$1 [PT,L]
Setup a Coming Soon page
There are some options available display a single page to your visitors while you site is under construction for a single domain:
- If the domain is launching but the entire site is not accessible, you could create a new branch with no Drupal code and place the
index.html
and assorted files in the docroot. An example of this would be thetag/WELCOME
tag inside your Acquia repository. - Create a page via Drupal. Visit the Basic Site Settings page at
/admin/config/system/site-information
and set the Default front page to that node. - Create a symlink of index.html in the docroot pointing to the index.html file within the sites directory. You'll probably need to use full URLs in the CSS and JS links to account for the symlink.