Ad

OctoberCMS | How Do I Enable A Directory For Download In OctoberCMS?

- 1 answer

I'm using XAMPP, and I need to enable a directory for download. I tried to give file permissions via FTP with FileZilla, but it didn't work.

I've seen this post, but didn't work for me: htaccess for download directory

themes/mytheme/uploads/ ** If I try to access file.pdf saved here (via url) I get 'File not found'

themes/mytheme/assets/images/ ** OK, I can download my file.pdf from this url

If I save the following .htaccess under /uploads , I still get 'File not found'

<FilesMatch "\.(.+)$">
    Order allow,deny
    Allow from all
    Satisfy any
</FilesMatch>

It seems October prevent direct access to certain directories from the url.

This is the original .htaccess from the web root:

<IfModule mod_rewrite.c>

    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    Options Indexes FollowSymLinks
    RewriteEngine On

    ##
    ## You may need to uncomment the following line for some hosting environments,
    ## if you have installed to a subdirectory, enter the name here also.
    ##
    # RewriteBase /

    ##
    ## Uncomment following lines to force HTTPS.
    ##
    # RewriteCond %{HTTPS} off
    # RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

    ##
    ## Black listed folders
    ##
    RewriteRule ^bootstrap/.* index.php [L,NC]
    RewriteRule ^config/.* index.php [L,NC]
    RewriteRule ^vendor/.* index.php [L,NC]
    RewriteRule ^storage/cms/.* index.php [L,NC]
    RewriteRule ^storage/logs/.* index.php [L,NC]
    RewriteRule ^storage/framework/.* index.php [L,NC]
    RewriteRule ^storage/temp/protected/.* index.php [L,NC]
    RewriteRule ^storage/app/uploads/protected/.* index.php [L,NC]

    ##
    ## White listed folders
    ##
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_FILENAME} !/.well-known/*
    RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/.*
    RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
    RewriteCond %{REQUEST_FILENAME} !/storage/temp/public/.*
    RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources)/.*
    RewriteCond %{REQUEST_FILENAME} !/plugins/.*/(assets|resources)/.*
    RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
    RewriteRule !^index.php index.php [L,NC]

    ##
    ## Block all PHP files, except index
    ##
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_FILENAME} \.php$
    RewriteRule !^index.php index.php [L,NC]

    ##
    ## Standard routes
    ##
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]


   ## RewriteCond %{REQUEST_URI} !^public
  ## RewriteRule ^(.*)$ public/$1 [L]    

</IfModule>

How do I access a file saved under /uploads ? Thank you

Ad

Answer

Hmm its quite easy

##
## White listed folders
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/.well-known/*
RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
RewriteCond %{REQUEST_FILENAME} !/storage/temp/public/.*

RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources)/.*

====> Do you see this line ^

RewriteCond %{REQUEST_FILENAME} !/plugins/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
RewriteRule !^index.php index.php [L,NC]

Replace that line with

RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources|uploads)/.*
                 ====> we are adding our folder to allow access  ^

It basically tells server that what files are in assets|resources|uploads let them allow access and let them download, instead just redirecting them to index.php

It should solve your issue

if any doubts please comment.

Ad
source: stackoverflow.com
Ad