Skip to main content
All CollectionsColdFusion
Enable HTML/HTM as CFML on Shared Accounts
Enable HTML/HTM as CFML on Shared Accounts
Updated over 4 years ago

On Hostek shared ColdFusion servers, the best way to process HTML (.html, .htm) files as ColdFusion/CFML (.cfm files) is by using a set of rewrite rules that route the HTML files through a ColdFusion “controller” script.

The main benefits of this approach:

  • Ease of implementation on a site-by-site basis

  • Works with any version of ColdFusion.

Implementing and Enabling HTML/HTM as CFML on a Shared Hosting Package

    1. Add Rewrite Rules to Route HTML Files through the CFM Controller.If you have a ‘.htaccess’ file in your webroot, add the rules below to the top of that file. Otherwise, create a file named ‘.htaccess’ (no single quotes) in your site’s web root and place the following rules within this file:

  • For Sites using .HTML Files

#Rewrite requests without script name to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /index.html [R]

# REDIRECT to change the address in the browser address bar
RewriteRule ^/htmlcontrol.cfm$ /$1.html [R]
#REWRITE so that the correct page executes when /cart is the URL
RewriteRule ^(.*)\.html htmlcontrol.cfm/?pageName=$1 [L]
  • For sites using .HTM Files

#Rewrite requests without script name to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /index.htm   [R]
 
# REDIRECT to change the address in the browser address bar
RewriteRule ^/htmlcontrol.cfm$   /$1.htm   [R]
 
# REWRITE so that the correct page executes when /cart is the URL
RewriteRule ^(.*)\.htm htmlcontrol.cfm/?pageName=$1   [L]

   
    2. Create the ColdFusion Controller Script (htmlcontrol.cfm)Now a script that process HTML files will need to be created. To do this, create a file named htmlcontrol.cfm within your site’s web root.  Place the following CFML code within the file (Once you have saved the controller script, your site will begin processing any ColdFusion/CFML code within your HTML files):

  • CFML for Sites Using .HTML Files

<cfinclude template="#URL.pageName#.html" >
  • CFML for Sites Using .HTM Files

<cfinclude template="#URL.pageName#.htm" >
Did this answer your question?