Link to home
Start Free TrialLog in
Avatar of thierry91
thierry91

asked on

how to make with apache + autoindex for *.txt files are downloaded and not opened

I have actived autoindex with commande +Indexes for one folder.
I want all file listed can be downloaded and not opened.

when files listed are *.txt when I click on the file is opened.
me whant when I click on *.txt this file are downloaded.
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

in the htaccess for that directory
/foo/.htaccess:
RemoveType .txt
Avatar of thierry91
thierry91

ASKER

no, this not work
after have added this in .htaccess is same. and same if I add this in httpd.conf.
SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
same this not work.
this is my mine part in my conf apache 2.4.3 :

<IfModule mime_module>
    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php .php3 .html .htm
    AddType text/html .gx .pube
    AddEncoding x-gzip .gz
    AddType application/x-javascript .js
    AddType text/css .css
    AddType text/xml .xml
    #AddHandler cgi-script .cgi
    #AddHandler type-map var
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml
    AddType audio/mpeg     .mp3 .MP3
    AddType audio/playlist .m3u .M3U
    AddType audio/x-scpls  .pls .PLS
    AddType audio/ogg .oga .ogg .spx .OGA .OGG .SPX
    AddType video/ogg .ogv .OGV
    AddType application/ogg .ogx .OGX
    AddType audio/flac .flac .FLAC
    AddType audio/annodex .axa .AXA
    AddType video/annodex .axv .AXV
    AddType application/annodex .anx .ANX
    Addtype application/xspf+xml .xspf .XSPF
    AddType texte/x-composant .htc .HTC
    AddType application/download-me .txt
    <files *.js.gz>
      AddType "text/javascript" .gz
      AddEncoding gzip .gz
    </files>

    <files *.css.gz>
      AddType "text/css" .gz
      AddEncoding gzip .gz
    </files>

    <files *.xml.gz>
      AddType "text/xml" .gz
      AddEncoding gzip .gz
    </files>
</IfModule>

Open in new window

can you please check what contentype header is send to your browser (use a FF add-on like firebug, LiveHTTPheader, etc.)
with firefox file txt is downloaded but not with IE, Chrome, Opera.



http://*********/too.txt

GET /too.txt HTTP/1.1
Host: ************
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://********/
Cookie: __utma=259398038.5993309.1306913933.1317908675.1326825895.27

HTTP/1.1 200 OK
Date: Mon, 28 Jan 2013 10:00:34 GMT
Server: Apache
Last-Modified: Sat, 26 Jan 2013 01:47:44 GMT
Etag: "c-4d4273aee0b89"
Accept-Ranges: bytes
Content-Length: 12
Keep-Alive: timeout=15, max=40
Connection: Keep-Alive
Content-Type: application/download-me
----------------------------------------------------------

Open in new window

http://*********/too.txt

GET /too.txt HTTP/1.1
Host: ************
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://********/
Cookie: __utma=259398038.5993309.1306913933.1317908675.1326825895.27

HTTP/1.1 200 OK
Date: Mon, 28 Jan 2013 10:00:34 GMT
Server: Apache
Last-Modified: Sat, 26 Jan 2013 01:47:44 GMT
Etag: "c-4d4273aee0b89"
Accept-Ranges: bytes
Content-Length: 12
Keep-Alive: timeout=15, max=40
Connection: Keep-Alive
Content-Type: application/download-me
----------------------------------------------------------

Open in new window

I have solved partialy the problem. now with this in .htaccess :

<FilesMatch "\.(?i:txt)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

Opera and IE display prompt for download file, BUT chrome NO.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My solution work for and with all browser