In my htaccess file, i want to respond with a http 403 code if users attempt to access a directory, however if they attempt to access a file, allow. How is this done?
Turn off the Indexes option . Directory listing pages will only be supplied if it is turned on.
Using mod_rewrite:
Enable mod_rewrite
If filesystem path matching request ( REQUEST_FILENAME
) is a directory ( -d
)
Send a 403 header (Forbidden - [F]
)
(Not sure what exactly to put as first two parameters to RewriteRule, so redirecting anything to root)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* / [F]
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.