I wish to protect folders such as /css
and /js
from listing directory contents to snoopers. Perhaps I could do this via PHP, but I need to use .htaccess
.
Desired:
Anyone browsing to http://example.com/css
should not see a listing of files, but is immediately redirected back to http://example.com
.
I have tried several variations on the following, but cannot seem to get it right:
.htaccess inside each private folder:
RewriteEngine On
Redirect 301 /. http://example.com
or, in the webroot:
RewriteEngine On
RewriteBase /
RewriteRule /(.*)$ /$1 [L,NC,R]
Note: I already have an .htaccess file in the webroot, which any additional mod_rewrite commands would need to accomodate:
RewriteEngine On
RewriteBase /
RewriteRule ^dev/(.*)$ /$1 [L,NC,R]
RewriteRule ^/(.*)$ /dev/$1 [L,NC]
You can create /css/.htacces
with this line:
ErrorDocument 403 http://example.com/
Options -Indexes
Do same in /js/.htaccess
file.
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.