homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

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

10+ Year Member

Msg#: 3566933 posted 6:23 pm on Feb 5, 2008 (gmt 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?



5+ Year Member

Msg#: 3566933 posted 12:14 pm on Feb 6, 2008 (gmt 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.



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

Msg#: 3566933 posted 10:33 pm on Feb 6, 2008 (gmt 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. :)


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved