Created
February 14, 2017 08:29
-
-
Save mhuber84/66f4e11af3c84ab91180a841c5d02911 to your computer and use it in GitHub Desktop.
Set download filename to pre last path segment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_headers.c> | |
<IfModule mod_rewrite.c> | |
RewriteCond %{REQUEST_URI} ([^/]+)/datasheet.pdf$ | |
RewriteRule ^.*$ - [E=DATASHEETNAME:%1] | |
RequestHeader set datasheetname "%{DATASHEETNAME}e" env=DATASHEETNAME | |
Header set Content-Disposition "attachment; filename=%{HTTP_DATASHEETNAME}e.pdf" env=HTTP_DATASHEETNAME | |
</IfModule> | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With this .htaccess rule, if the path to your pdf is "http://domain.tld/path/to/my/superduper/datasheet.pdf", the download will get the filename "superduper.pdf".
I work with Apache 2.4 and PHP 7.0 as fcgid. If the file is a static file on the disc (no php involved) or the header is set in the vhost configuration, then the workaround with the RequestHeader is not needed. The pdf is generated dynamically by TYPO3, but the "Header set" didn't work as soon as PHP was called. So it has nothing to do with TYPO3.