Subfolder directory browsing in Apache2 - apache

Got a folder at http://myserver/folder/, I have disabled directory browsing for that folder.
But I want to enable directory browsing for the subfolders of http://myserver/folder/
How can I do this??
Thanks.

here's a working simple solution:
<Directory /path/to/docroot/folder>
Options -Indexes
</Directory>
<DirectoryMatch /path/to/docroot/folder/(.)*/>
Options +Indexes
</DirectoryMatch>

If you do not control apache, you can do this in a per-directory basis in your own files adding .htaccess file in the corresponding directory containing
Options +Indexes

Here is an option that you can use from .htaccess:
Options +Indexes
RewriteRule ^$ - [F]

You can just change the permissions of the respective folders. However, if you don't want to allow directory browsing at the /folder/ level, they'll need some link or way to get inward to the folders where you do allow browsing.

You can do this with an .htaccess file in each subfolder or at the top of each subfolder hierarchy. http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride ~ assuming apache

Your mileage might vary ...
.htaccess how no effect
neither did
Options +Indexes
but renaming index.html to _index.html display the files and folders in the browser

Another way is, if you have a directory you don't want browseable, create an empty index.html file in it, hopefully apache will pick that up and serve it instead :)

For any directory where you want to have the ability to list the directory, simply navigate there then execute this command:
echo "Options +Indexes" >.htaccess

Related

Set IndexIgnore inside httpd.conf

I want to prevent directory file listing in all of my folders, so when a user types http://example.com/thisDoesNotExists/, the directory file listing do not show up.
According to a tutorial all I have to do is set IndexIgnore *
I try to set it in the httpd.conf, so I do
<IfModule mod_autoindex>
IndexIgnore *
</IfModule>
at the bottom of the httpd.conf.
It does not work. I get my 404errorPage.html without any styles.
How can I fix this? Thanks.
Disclaimer : I try to set this in httpd.conf and not htaccess because "You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance." According to this.
Your <IfModule> argument is wrong so the enclosing directive is never evaluated. The argument either needs to be the modules name (you can see
this in the corresponding LoadModule) or the main source filename.
Both "autoindex_module" and "mod_autoindex.c" work.
Here is another way to do it:
You should edit /etc/httpd/conf/httpd.conf, find the code block with
<Directory "/var/www/html">
Options Index FollowSymLinks
</Directory>
You should remove the Index in there then restart your httpd service by
sudo service httpd restart

How do I write an .htaccess file so that it can proxy images outside of the web root on an Apache server?

I want to proxy a bunch of images on my Apache server so that they are not stored in the webroot.
Specifically, I have all my images in the following folder on my Linux server:
/var/www/img/
However, I want it so that when a user goes to mydomain.com/img/img1.jpg (which has the server path /var/www/html/img/img1.jpg), it references the following file outside of the webroot:
/var/www/img/img1.jpg
It seems like this is possible using the ProxyPass and ProxyPassReverse rules in an .htaccess file (source: https://httpd.apache.org/docs/2.4/rewrite/avoid.html#proxy), but I'm having trouble understanding their syntax and which path goes where, etc.
Given my above situation, could someone please provide some explicit code that I can write into an .htaccess file to achieve what I want?
Edit: I just solved this problem by adding the following one line to my Apache httpd.conf file, and then restarting the server:
Alias "/img" "/var/www/img"
Where the /img part refers to the img directory in my webroot, and the /var/www/img part refers to the Linux filesystem directory I want to point to with the actual files in it.
Best way is to add a symbolic link to your other folder:
ln -s /my/target/folder /var/www/html/mynewfolder
If you can edit the Apache conf file for the server you need to add the FollowSymLinks directive in the directory block:
<Directory "/var/www/html/">
AllowOverride All
Options FollowSymLinks
</Directory>
You might also be able to add that to your .htaccess file as Options +FollowSymLinks if you can't edit the Apache file
You can try doing this with the PassThrough PT flag and mod_rewrite.
You create an alias to the actual path and then use it in the rule.
Alias "/img" "/var/www/img/"
RewriteRule "img/(.+)\.(jpe?g|gif|png)$" "/img/$1.$2" [PT]
See how that works for you.

Preventing directory listing by redirecting?

I want to use .htaccess to prevent directory listing.
I've got pages within /location/ but I don't have an index file. So I want to redirect to /location/about.php for example.
Is there a way to do this, without creating an index.html and redirecting requests to that?
Thanks for the help!
If you're asking for a file in place of 'index.html', see "DirectoryIndex" to tell it what files to use in place of 'index.html':
DirectoryIndex about.php index.html
Options –Indexes
... if you're trying to redirect all directories to a single page, then I'd cheat and do the following, which will mostly do what you're asking for:
Options +Indexes
IndexOptions +SuppressHTMLPreamble
IndexIgnore *
HeaderName /includes/header.html
ReadmeName /includes/readme.html
... and set /includes/header.html with whatever message you want (or containing a meta-redirect), and /includes/readme.html to be blank.
I know this is an older thread but I just had to implement something similar and did it the following way:
Options -Indexes
ErrorDocument 403 /location/about.php
Basically, Options -Indexes prevents directory listing and ErrorDocument 403 rewrites the default 403 message.
Changing DirectoryIndex and Options works, but using mod_alias means that you don't have to change it back in nested directories.
Redirect 303 /location/ /location/about.php
Here is a direct link to what you need:
http://www.webweaver.nu/html-tips/web-redirection.shtml
If you need something more advanced to handle parameters or need to remap old URLs to new ones, you can use URL rewriting:
http://corz.org/serv/tricks/htaccess2.php
Prevent directory listing (or return an empty directory listing):
http://www.besthostratings.com/articles/prevent-directory-listing.html

Removing .htaccess Authentication Restrictions

I have a project that has .htaccess Authentication but i want to remove it for a certain assets folder.
i tried adding a htaccess in that folder with :
AuthType none
Satisfy Any
Allow from All
Order Allow, Deny
but it doesnt seem to work :(
Any thought on this. Thank you so much
Edit
The directory i am trying to unprotect is not a real directory, but a rewrite rule.
I dont have access to httpd.conf
Without seeing your full .htaccess I'm guessing, but what about something like this:
RewriteEngine On
RewriteRule ^assets/ - [E=allow-assets:1]
Allow from env=allow-assets
That could go in the .htaccess of the parent directory, not assets.
You could possibly do this if you have access to /etc/httpd.conf -- do you?

htaccess file restriction

I have a directory on my webserver. It does not have an index page. so when u access the directory via a web browser it lists the files in it. Now i want to create a htaccess file that can block the directory listing so that when you access it via the web browser, the files in the directory would not be listed but would be able to access the files by appending the name of the file you wish to access to the url making it a full part to the file. Also the htaccess file should be able to restrict access from all but files with a particular extention. Thanks.
Options -Indexes
Order allow,deny
Deny from all
<Files "*.gif">
Allow from all
Deny from none
</Files>
You can turn off the file listing for a particular directory in the directory's .htaccess with
Options -Indexes
OR
You could just put an empty index.html file in the directory you want to protect.
In the .htaccess file in your directory just put
Options -Indexes
As stated before.
Edited to remove the wrong htaccess setting. Again sorry