十月CMS |如何在 OctoberCMS 中启用下载目录?

OctoberCMS | How do I enable a directory for download in OctoberCMS?

我正在使用 XAMPP,我需要启用一个目录以供下载。 我尝试使用 FileZilla 通过 FTP 授予文件权限,但没有成功。

我看过这个 post,但对我没用:htaccess for download directory

themes/mytheme/uploads/ ** 如果我尝试访问此处保存的 file.pdf(通过 url),我会得到 'File not found'

themes/mytheme/assets/images/ ** 好的,我可以从这个 url

下载我的 file.pdf

如果我将以下 .htaccess 保存在 /uploads 下,我仍然会得到 'File not found'

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

October 似乎阻止从 url.

直接访问某些目录

这是原文.htaccess来自网络根目录:

<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}/ [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/ [L]    

</IfModule>

如何访问保存在 /uploads 下的文件?谢谢

嗯,很简单

##
## 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

它应该可以解决您的问题

如有疑问请评论。