Force a File to Display Instead of Executing

November 5th, 2007

If you’re like me, you run a site written in PHP. Sometimes I offer PHP scripts to my readers and want them to be able to download them, but if I post a link, the script is executed instead. You can prevent this action with a small .htaccess tweak.

If you install this tweak in the .htaccess file at the root of your domain, it will be applied site-wide, however, you may find it better to keep it within certain subdirectories that are intended to house publicly available scripts.

The following example would force PHP and Python or Perl CGI scripts to display as text in the browser rather than executing as is there default action.

RemoveHandler cgi-script .pl .py .cgi
RemoveHandler application/x-httpd-php .php
Please use the trackback link when linking to this post.

Related Posts:

Add to Technorati Favorites

One Response to “Force a File to Display Instead of Executing”

  1. Harsh Says:

    Hi.. I don’t know your name,

    but that you very much for your short description about how to display file instead of executing that and how to download instead of opening. That helps me a lot…

    thank you very much..
    Harsh

Leave a Reply

.htaccess Apache article articles by Nilpo ASP ASP Free automation clipboard desktop Dev Shed docx drive Internet Explorer Microsoft PHP registry remove script scripting text tutorial tweak tweets Twitter UAC updates User Account Control VBS VBScript vista volume Windows Windows 7 Windows 2000 Windows Guru Windows Script Windows Script Host Windows Scripting Windows Vista Windows XP Word WScript wscript.exe WSH XP