Using Apache. How can I allow access to /storage/ but deny access to /.storage/ when /storage/ is an alias for /.storage/subdomain/?
# Define alias based on subdomain
RewriteCond %{HTTP_HOST} ^([^.]+)$
RewriteRule ^storage/(.*)$ ".storage/%1/$1" [QSA,L]
# Forbid access to
RewriteCond %{REQUEST_URI} ^/\.storage/
RewriteRule ^ - [F,L]
Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs. We need to fix regex for getting sub-domain first then we need to change "
from rules and add an additional condition to checks to make sure users are not able to access actual folder directly.
RewriteEngine ON
# Define alias based on subdomain
RewriteCond %{HTTP_HOST} ^(?:www\.)(.*)$ [NC]
RewriteRule ^storage/(.*)$ .storage/%1/$1 [NC,QSA,L]
# Forbid access to
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^\.storage - [F,NC,L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.