【问题标题】:How to allow users to access a folder, through ".htaccess"?如何允许用户通过“.htaccess”访问文件夹?
【发布时间】:2016-11-27 01:29:57
【问题描述】:

我在我的域中创建了一个文件夹,名为:SquirrelMail

我有这个.htaccess

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

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 /

##
## Black list protected files
##
RewriteRule ^themes/.*/(layouts|pages|partials)/.*.htm index.php [L,NC]
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 and files
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !\.map$
RewriteCond %{REQUEST_URI} !\.ico$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteCond %{REQUEST_URI} !\.jpeg$
RewriteCond %{REQUEST_URI} !\.bmp$
RewriteCond %{REQUEST_URI} !\.png$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteCond %{REQUEST_URI} !\.svg$
RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.less$
RewriteCond %{REQUEST_URI} !\.scss$
RewriteCond %{REQUEST_URI} !\.pdf$
RewriteCond %{REQUEST_URI} !\.swf$
RewriteCond %{REQUEST_URI} !\.txt$
RewriteCond %{REQUEST_URI} !\.xml$
RewriteCond %{REQUEST_URI} !\.xls$
RewriteCond %{REQUEST_URI} !\.eot$
RewriteCond %{REQUEST_URI} !\.woff$
RewriteCond %{REQUEST_URI} !\.woff2$
RewriteCond %{REQUEST_URI} !\.ttf$
RewriteCond %{REQUEST_URI} !\.flv$
RewriteCond %{REQUEST_URI} !\.wmv$
RewriteCond %{REQUEST_URI} !\.mp3$
RewriteCond %{REQUEST_URI} !\.ogg$
RewriteCond %{REQUEST_URI} !\.wav$
RewriteCond %{REQUEST_URI} !\.avi$
RewriteCond %{REQUEST_URI} !\.mov$
RewriteCond %{REQUEST_URI} !\.mp4$
RewriteCond %{REQUEST_URI} !\.mpeg$
RewriteCond %{REQUEST_URI} !\.webm$
RewriteCond %{REQUEST_URI} !\.mkv$
RewriteCond %{REQUEST_URI} !\.rar$
RewriteCond %{REQUEST_URI} !\.zip$
RewriteCond %{REQUEST_URI} !docs/.*
RewriteCond %{REQUEST_URI} !themes/.*
RewriteRule ^ index.php [L,NC]

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

每次,我都会去:mydomain.com/squirrelmail,我收到一个Page Not Found 错误。

我的.htaccess 中应该有什么才能访问我的SquirrelMail 文件夹?

您的帮助将不胜感激!

.htaccessoctoberCMS 默认值。我想通过创建一个文件夹来安装 SquirrelMail。我没有访问子域的权限,这就是我这样做的原因。

【问题讨论】:

  • mydomain.com/squirrelmail/ 目录下是否有 index.html 或 index.php?您是否想让它查找具有以下内容的索引:RewriteRule ^ index.php [L]
  • @Tsangares 是的,我的 /squirrelmail/ 目录中有一个 index.php。

标签: php apache .htaccess mod-rewrite octobercms


【解决方案1】:

10 月稳定版中的.htaccess 文件使用了更新的方法,更符合您的要求。请参阅下面的新白名单方法:

##
## White listed folders
##
RewriteCond %{REQUEST_FILENAME} -f
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]

只需为您的文件夹添加一个新行,这应该允许所有文件通过。

RewriteCond %{REQUEST_FILENAME} !/myfolder/.*

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    • 2013-07-31
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    相关资源
    最近更新 更多