Parse html or htm files as php using htaccess

spiros · 1 · 8462


  • Administrator
  • Hero Member
  • *****
    • Posts: 827349
    • Gender:Male
  • point d’amour
This advice concerns web site owners who want to use php scripts in their html pages and do not want to rename them with a php extension.

There is a very simple solution. It applies only to *nix installations (Unix / Linux) and it involves the creation of an htaccess file.

  • Create a file with notepad
  • Save it as .htaccess (this means that if its extension is txt then it should be replaced with htaccess).
  • Add this declaration in the file AddType application/x-httpd-php .htm .html This ensures that files with the extension .htm or .html are parsed as php files. If you want only files with the .html extension to be parsed you simple remove the .htm bit.
  • Upload the .htaccess file on your root

Now, if you use an FTP client you might be unable to see the .htaccess file. This is in order to protect it from accidental deletion. You need to use a mask in your FTP client in order to be able to see it. For example with WS_FTP you go to the startup tab and on the Remote file mask box you enter -a.

If you use  CuteFTP:

Click "Edit..." to edit your settings
Check the "Enable Filter" box and click on "Filter..."
Check the "Enable Remote Filters" box
Enter "-a" as the remote filter
Depending on what else you've done, it MAY be necessary to uncheck "Enable Local Filters"
Click OK, click OK, and then reconnect.
« Last Edit: 31 Oct, 2005, 12:51:35 by spiros »


Search Tools