How can I allow directory listing in Apache for a specific (root) folder and its subfolders, but without showing a link to parent of that root folder. When user is in a subfolder, the 'Parent Directory'link is displayed to navigate to its parent, but when user is at the root folder I need to remove/hide this 'Parent Directory' link so that user cannot move above that 'root' hierarchy.
I just ran into the same issue, and this was the first search result, so I thought I'd share my solution. I don't have access to httpd-configs in my case, so I went with a different approach.
Because I won't be maintaining the indexed directory tree, I needed a solution that could exist just in the index root without any specific knowledge of its sub-directories. However, it does use an absolute path to the index root, so if your parent folder structure changes a lot, it may not work for you.
What I came up with was using a CSS URL attribute selector to hide the "Parent Directory" link when it led to the parent of the index root. It leaves a blank row, but at least it's not as intimidating as the "403 FORBIDDEN" error a user gets if they click Parent Directory one too many times.
Theoretically, the fix should be as simple as adding one line to your index root's .htaccess file:
IndexHeadInsert "<style type=\"text/css\">a[href=\"/absolute/path/to/index/root/parent/\"] {display: none;}</style>"
However, it seems that simple solution doesn't work in IE because the default doctype of the html that Apache spits out is too old to use attribute selectors.
Instead, we have to surround Apache's generated code with our own doctype using the HeaderName and ReadmeName keywords in the htaccess file. I went with the HTML5 doctype, although there may be a more appropriate one that works.
.htaccess file:
Options +Indexes
IndexIgnore "_index_header.html" "_index_footer.html"
HeaderName "/absolute/path/to/root/index/_index_header.html"
ReadmeName "/absolute/path/to/root/index/_index_footer.html"
IndexOptions +SuppressHTMLPreamble
_index_header.html file:
<!DOCTYPE html>
<html>
<head>
<title>title</title>
<style type="text/css">
a[href="/absolute/path/to/index/root/parent/"] {display: none;}
</style>
</head>
<body>
_index_footer.html file:
</body>
</html>
(Note that the CSS selector is to the index root's parent)
Works in all of the latest browser versions I tested it on (FF, IE, Chrome, Safari, Opera), and also all the way back to IE 7.
Also, now that you went through all the trouble of creating those files, you might as well make your index more snazzy. The apache doc on mod_autoindex has a bunch of options you can use to tweak things, on top of what you can do with CSS.