... and Settling In
Once you have uploaded the HTML Master Pages program files to your web-site, you'll need to tell the Apache web server how to use them. This is easy as long as your web hosting provider allows you some control over the Apache web server's behavior (usually by permitting you to create a file named .htaccess
in the root directory of your web-site). The exact name of your Apache configuration file can be changed by your web hosting provider, so you may need to discover the permissible name if this doesn't work as expected.
Add the following lines to your Apache configuration file:
Analysis
The directives in this configuration file provide the following:
-
# Enable HTML Master Pages
An innocuous comment that is used to inform others (and remind yourself later in case you forget) just what this section of settings will do. -
Action html-master-pages /demuxer.php
Defines an Action namedhtml-master-pages
which instructs Apache to use the/demuxer.php
program to read and process files that are mapped to it by the next three AddHandler lines. If you opted to upload the HTML Master Pages files to a directory other than the root of your web-site, you'll need to set the path here accordingly. Note that this path is relative to the root directory of your web-site, not the web server. -
AddHandler html-master-pages .htm
Instructs Apache to use thehtml-master-pages
Action to process any file that is named with a.htm
extension (a short-hand extension for HTML files). -
AddHandler html-master-pages .html
Instructs Apache to use thehtml-master-pages
Action to process any file that is named with a.html
extension (a normal extension for HTML files). -
AddHandler html-master-pages .phtml
Instructs Apache to use thehtml-master-pages
Action to process any file that is named with a.phtml
extension (an extension for HTML files that may contain PHP code). You may omit this line if you know without any shadow of doubt that you'll never want to use PHP to generate dynamic HTML content. -
DirectoryIndex index.php index.phtml index.html index.htm
Enables the named files to be loaded automatically by Apache whenever an otherwise empty directory name is requested by visitors. Because we are asking HTML Master Pages to handle all*.htm
,*.html
, and*.phtml
files and we know PHP is enabled, we are also allowing Apache to use allindex.[php|phtml|html|htm]
variants as the default file that will be processed whenever a visitor requests a path by its directory name only. This is the difference between allowing visitors to access http://your-site/ or forcing them to fully type http://your-site/index.html to gain the same benefit. This is a convenience for you and your visitors which may not be necessary in every situation. For example, some sites (particularly of the Microsoft IIS family) may adddefault.php default.phtml default.html default.htm
to this list.
Notice we specifically do not map .php
files to HTML Master Pages. An in-depth look at why we don't is covered in the Using With PHP section but for now, it is best to trust that doing so is a bad idea. If you have a bunch of .php
files that you are actually using to generate HTML, it may be better for you to rename those files to have .phtml
extensions than to just map .php
to HTML Master Pages.
Of course, you may elect to create any mapping that better fits your situation. If you would rather not override the default Apache handlers for your HTML files, you may prefer to dedicate a new file extension like .resource
to trigger HTML Master Pages. Whatever file extension you choose needs only be used with your resource documents but you must realize that using non-standard file extensions may make it more difficult for visitors to hand-type what would otherwise be obvious URLs into your web-site. Your visitors should not need to access your Master Pages directly, so your Master Page files need not use the same file extension(s) as your resource documents.