开发者

Allow only direct access on a specific folder name via .htaccess

I need to allow direct access on a specific folder name (and subcontents) via .htaccess, and deny all other.

To start, my current .htaccess is:

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

My file structure is, for instance:

    modules/
        core开发者_C百科/
            _test/
            publics/
                file.txt
        other/
            _whatever/
                publics/
                    more.txt
            publics/
                sub/
                    file.txt
                other.txt
    .htaccess

I could not access anything, except by files and folders that are in publics folder. On this example, I could access, without problem:

  • modules/core/publics/ [dir]
  • modules/core/publics/file.txt
  • modules/other/_whatever/publics/ [dir]
  • modules/other/_whatever/publics/more.txt
  • modules/other/publics/ [dir]
  • modules/other/publics/sub/ [dir]
  • modules/other/publics/sub/file.txt
  • modules/other/publics/other.txt

I could not have access to any file or folder.

I guess that we will need regular expression, but I don't know how I can use this on mod_rewrite to works like I want.

Some suggestion?


A slight modification to your current htaccess. Any access not under a publics folder will be redirected to index.php:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜