Search code examples
.htaccesscontent-disposition

How to grant exception to Content-Disposition attachment?


I used this code in .htaccess to force all files to download --

ForceType application/octet-stream
Header set Content-Disposition attachment

However, how can I grant an exception to index.php for it not to download. I know that FilesMatch can be used but I need all files to download except index.php. I can't possible list out all the file extensions in FilesMatch. Thank in advance!


Solution

  • Yes, you can negate in FilesMatch directive:

    <FilesMatch "(?!index\.php).*">
        ForceType application/octet-stream
        Header set Content-Disposition attachment
    </FilesMatch>