I currently have in a server files in this format



  • group_no an integer (NN)
  • date format YYYY-MM-DD
  • file_no an integer (NN)



And I would like that the downloaded file is something like YYYY-MM-DD-NN-NN-file.txt

I'm not sure if with a htaccess Rewrite rule I could accomplish this

Theorically I could look for 3 regex groups, the first the group_no NN after finding files/ in the URL and the second group after this before finding the next / and the 3rd group after the last / then just adding something like $1-$2-$3

I've tried something like this

RewriteEngine on
RewriteBase /
RewriteRule ^.*\/files\/(.+)\/(.+)\/(.+txt)$ $1-$2-$3 [L]

But it doesn't seem to work. https://regex101.com/r/hFrffK/1

Any ideas?

  • Please explain "doesn't seem to work". What results do you get? And also, what's the actual file layout on disk, on the server? Mar 18, 2021 at 17:58
  • @user1686 I think this solution won't do the trick. Not sure that through rewrite rules exclusively It's possible to do this. After some reading around I'm starting to believe that headers should be also introduced.
    – SirLouen
    Mar 19, 2021 at 11:08


You must log in to answer this question.

Browse other questions tagged .