Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.htaccess rewrite rule to append the date to the filename, using Content-Disposition
#1
PHP Code:
RewriteEngine On
RewriteRule 
([^/]+)\.pdf$ - [E=FILENAME:$1]
<
FilesMatch "\.(?i:pdf)$">
    Header set Content-Type application/octet-stream
    Header onsuccess set Content
-Disposition "expr=attachment; filename=\"%{ENV:FILENAME}-%{TIME_YEAR}-%{TIME_MON}-%{TIME_DAY}\.pdf\"" env=FILENAME
</FilesMatch

The Apache documentation for the Header directive shows that the %{VARNAME}e format specifier should be used for placing environment variables in the Header value. However, since the value is provided via an ap_expr expression in my code sample, the ap_expr function env (or maybe reqenv) should be used instead. The Header directive documentation says that within ap_expr expressions:

PHP Code:
Function calls use the %{funcname:argsyntax rather than funcname(arg). 
All resources on the forum clean. Sometimes Virus total give false positives. Also developers may insert backdoors, if you find it, contact me.
Reply


Bookmarks

Possibly Related Threads…
Thread Author Replies Views Last Post
HELP .htaccess rewrite rule to append the date to the filename, using Content-Disposition Shedrach 0 614 05-18-2023, 01:46 AM
Last Post: Shedrach
How to Force Download files via .htaccess Shedrach 0 653 05-18-2023, 01:39 AM
Last Post: Shedrach
Wordpress default htaccess code Shedrach 0 559 05-18-2023, 01:32 AM
Last Post: Shedrach
htaccess redirect full url to another url Shedrach 0 631 04-25-2023, 09:36 AM
Last Post: Shedrach



Users browsing this thread: 1 Guest(s)