Force a File to Display Instead of Executing

November 5th, 2007
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5 out of 5)
Loading ... Loading ...

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

Leave a Reply