Show file in plain text instead of execute/download in Apache

PHP files, PDF files and others will all be executed or downloaded. If you want to show a file in plain text instead, such as a PHP file, you should instruct Apache to do so.

In your .htaccess file, you should instruct your webserver to serve files with a certain extension as plain text to the user. In the example below, we want Apache to show all PHP files instead of being executed by the PHP engine.

AddType text/plain php

Additionally, you can add multiple filetypes. Simply add the extension name at the end:

AddType text/plain php html sh xml

 

Author Bio

Thank you for your interest in my blog! On this miniblog, I write mostly short (technical) blog posts that might interest other people. Read more about me or feel free to contact me.

 

One thought on “Show file in plain text instead of execute/download in Apache

Leave a Reply

Your email address will not be published. Required fields are marked *