Force a File to Display Instead of Executing

Written by Nilpo in Apache | 1 Comment

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

Like the read? Share it!

1 Comment

  • 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..

Leave a Reply


Wanna say hello?
Drop us a line!

You'll find us here

1 Microsoft Way,
WA 98052, United States