0

I currently have in a server files in this format

https://example.com/files/{group_no}/{date}/{file_no}-file.txt

Being:

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

Example:

https://example.com/files/12/2021-03-17/01-file.txt

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?

2
  • 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? – user1686 Mar 18 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 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.