chamilo / chamilo-lms

Chamilo is a learning management system focused on ease of use and accessibility
https://chamilo.org
GNU General Public License v3.0
792 stars 478 forks source link

Optimization Guide: Error in RewriteRule to speed up loading media files, including fix #5637

Open KrSi78 opened 3 months ago

KrSi78 commented 3 months ago

The topic Removing files download permissions check in the Chamilo Optimization Guide (/documentation/optimization.html if not deleted after installation) suggests to introduce the following rewrite rule:

RewriteRule ^courses/([^/]+)/document/(.*([\.js|\.css|\.png|\.jpg|\.jpeg|\.gif|\.mp4|\.webm|\.avi|\.mpeg|\.mp3|\.wav|\.ogg]))$ app/courses/$1/document/$2 [QSA,L]

Unfortunately, that results in a 403 error when for a given course a document subfolder is called using a path (/courses/course_code/document/folder) instead of calling the PHP-script (/main/document/document.php?cidReq=....).

I've asked ChatGPT for a correction and it came up with the following:

RewriteRule ^courses/([^/]+)/document/(.*\.(js|css|png|jpg|jpeg|gif|mp4|webm|avi|mpeg|mp3|wav|ogg))$ app/courses/$1/document/$2 [QSA,L]

The corrected rewrite rule expects a dot followed by one of the extensions listed, but doesn't fire when the dot is missing, exactly what we want so when linking to a subfolder, document.php is called anyway.

ywarnier commented 3 months ago

Hi @KrSi78 Thanks. Just to be sure to understand you, you mean that when you only ask for a subfolder (not a file), the existing rule doesn't work, right? (it fires but generates a 403) Asking so that I can reproduce it quickly.

KrSi78 commented 3 months ago

That's correct. We use links on the home page of the courses to link to specific folders. The existing rule fires but results in a 403 as directory listing is turned off. The rule ChatGPT suggests tackles this as the rule doesn't match when the URL doesn't end on a dot succeeded by one of the media file type extensions mentioned.

Op za 6 jul 2024 om 17:35 schreef Yannick Warnier @.***

:

Hi @KrSi78 https://github.com/KrSi78 Thanks. Just to be sure to understand you, you mean that when you only ask for a subfolder (not a file), the existing rule doesn't work, right? (it fires but generates a 403) Asking so that I can reproduce it quickly.

— Reply to this email directly, view it on GitHub https://github.com/chamilo/chamilo-lms/issues/5637#issuecomment-2211799410, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEBIW35SLXUO7BOWAEBC5W3ZLAFEXAVCNFSM6AAAAABKNDEGDOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJRG44TSNBRGA . You are receiving this because you were mentioned.Message ID: @.***>