禁止访问目录,但不是别名?

Forbid access to directory, but not alias?

使用阿帕奇。当 /storage/ 是 /.storage/subdomain/?

的别名时,如何允许访问 /storage/ 但拒绝访问 /.storage/
# Define alias based on subdomain
RewriteCond %{HTTP_HOST} ^([^.]+)$
RewriteRule ^storage/(.*)$ ".storage/%1/" [QSA,L]

# Forbid access to 
RewriteCond %{REQUEST_URI} ^/\.storage/
RewriteRule ^ - [F,L]

根据您显示的示例,您能否尝试以下操作。请确保在测试 URL 之前清除浏览器缓存。我们需要先修复正则表达式以获取子域,然后我们需要从规则中更改 " 并在检查中添加附加条件以确保用户无法直接访问实际文件夹。

RewriteEngine ON
# Define alias based on subdomain
RewriteCond %{HTTP_HOST} ^(?:www\.)(.*)$ [NC]
RewriteRule ^storage/(.*)$ .storage/%1/ [NC,QSA,L]

# Forbid access to 
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^\.storage - [F,NC,L]