【问题标题】:Allow only direct access on a specific folder name via .htaccess仅允许通过 .htaccess 直接访问特定文件夹名称
【发布时间】:2011-08-05 14:44:27
【问题描述】:

我需要允许通过 .htaccess 直接访问特定文件夹名称(和子内容),并拒绝所有其他。

首先,我当前的.htaccess 是:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . index.php [L]

我的文件结构是,例如:

    modules/
        core/
            _test/
            publics/
                file.txt
        other/
            _whatever/
                publics/
                    more.txt
            publics/
                sub/
                    file.txt
                other.txt
    .htaccess

除了publics 文件夹中的文件和文件夹外,我无法访问任何内容。在这个例子中,我可以毫无问题地访问:

  • modules/core/publics/[目录]
  • modules/core/publics/file.txt
  • modules/other/_whatever/publics/[目录]
  • modules/other/_whatever/publics/more.txt
  • 模块/其他/publics/ [目录]
  • modules/other/publics/sub/ [目录]
  • modules/other/publics/sub/file.txt
  • modules/other/publics/other.txt

我无法访问任何文件或文件夹。

我想我们将需要正则表达式,但我不知道如何在 mod_rewrite 上使用它来像我想要的那样工作。

有什么建议吗?

【问题讨论】:

标签: .htaccess mod-rewrite


【解决方案1】:

对您当前的 htaccess 稍作修改。任何不在 publics 文件夹下的访问都将被重定向到 index.php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !publics/
RewriteRule . index.php [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 2016-11-27
    • 1970-01-01
    • 2016-03-23
    • 2012-03-06
    相关资源
    最近更新 更多