Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

How can i display files without ending as text/plain?

6:23 pm on Feb 5, 2008 (gmt 0)

New User

10+ Year Member

joined:Oct 15, 2003
votes: 0

I have a folder on my server with program files. I want them all the be displayed as text files. This works so far

AddType text/plain .cgi .py .tmpl

But there are also some files without a *.py or *.cgi ending like htaccess. How can i display those files as text/plain?

12:14 pm on Feb 6, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 23, 2008
posts: 56
votes: 0

Hey Markus,

'.htaccess' is basically special, if chown'ing, chgrp'ing and chmod'ing it as openly as possible doesn't work, as it shouldn't, then you might find that you need to change it's name to 'htaccess.txt' and write the explanation in it, ie;

# the proper name of this file in a Linux (Google: LAMP) setup is .htaccess
# but Apache won't show it to you with it's right name, not even in a subdirectory.

I'm pretty sure Apache won't display the contents of any file named '.htaccess' no matter who owns it or how 777 it's MOD is but if anyone knows better I'd appreciate them trumping me just to be corrected alone.

If I wanted to show everybody the contents of my 'special' files, I would be inclined to mark them up into suitable HTML to provide navigation surrounding the <code></code> sections and not actually try to expose files of those extensions 'using their own extensions' so to speak.


10:33 pm on Feb 6, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

What kind of files are these extension-less files? If they are text/plain, then give the *files* a .txt extension, and use an internal rewrite so that the extensionless URL maps to the file with an appropriate extension.

file foo --> renamed to --> foo.txt

mod_rewrite code:

RewriteRule ^foo$ /foo.txt [L]

The URL is still example.com/foo, but the filename is now foo.txt. Since MIME-types are set according to the filetype and not the URL, a request for example.com/foo will now return a proper Content-Type: text/plain response header.

By the way, .htaccess is its own extension; It doesn't have a filename. :)