Reputation: 33
I can't figure out how to make filenames with spaces in them correctly named when downloaded. The name gets broken at the first space. eg. the file
how are you.pdf
is downloaded as
how
Below is my code. I have tried many things and none have worked this far.
RewriteEngine On
##RewriteBase /
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?consciousnesscoachingacademy.com [NC]
RewriteRule \.(.*)$ - [NC,F,L]
RewriteCond %{QUERY_STRING} ^filename=(.*)$
RewriteRule ^download\.php$ %1
RewriteRule (.*) - [E=file:$1]
Header set Content-type "octet-stream"
Header set Content-disposition "attachment; filename=%{file}e" env=file
Upvotes: 3
Views: 293
Reputation: 784878
Try this code:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?consciousnesscoachingacademy.com [NC]
RewriteRule \.(.*)$ - [NC,F,L]
# file download (attachment)
RewriteCond %{THE_REQUEST} /download\.php\?filename=(.+)\ HTTP/ [NC]
RewriteRule ^download\.php$ %1? [E=file:%1]
Header set "Content-disposition" "attachment; filename=\"%{REDIRECT_file}e\""
Header set "Content-type" "octet-stream"
Upvotes: 1