Quick TipWritten on

Render a static HTML file from PHP

Let's say you have a full static site and you need a single file to handle a submission or an API call or something.

Here is the php part -- Let's say it's called index.php:

<?php

  if (!empty( $_POST )) {
      // Handle the business side of the request here ...

      // Render the thanks page
      readfile("thanks.html");
      exit(0);
  }

  // Render the form or stuff
  readfile(contact.html");

And the .htaccess part for apache users is straight forward:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]