I am currently browsing the files (mostly images) on our server using HTTP, in the most primitive way (a very inefficient way).
To quickly glance a file, I need to click on and open it. Then exit, onto the next file. Very inefficient.
Is there a way that I can preview these files without opening them, just like what we do on our Mac/Windows system.
You could use Fancybox to get both a thumbnail view, and to open images without leaving the page. You can configure Apache to display your directory as a gallery, and add in thumbnails of your image into the DOM.
Try the instructions found here. The demo on that page doesn't seem to be working, but the instructions do work. The instructions there don't cover adding thumbnails, but in my abbreviated instructions below I added in a step to get them:
Download Fancybox
Create a fancybox directory at the root level of your site, and add the files from the Fancybox download.
Create a fancybox.html file in the fancybox directory and load the Fancybox library and set the config options. See the example here.
(My addition) Add a line to fancybox.html to insert a thumbnail into the Apache directory listing. Here's just a simple line you might add after line 26 in the linked example file:
$(this).html("<img src='"+ $(this).attr('href') +"' width='200'>" + title);
Create a .htaccess file in your image directory (and be sure .htaccess files are usable by Apache)
Add these lines to the .htaccess file:
Options +Indexes
ReadmeName /fancybox/fancybox.html
Navigate to your image directory
You can modify the Apache directory listing page to make it as pretty as you like. See this article on styling the directory listing. Probably any other gallery library you like could be used with a similar method, the important thing is that the ReadmeName option lets you inject javascript and css which you can use to manipulate the DOM.
Related
I took over a website which I'm supposed to admin and somebody brought to my attention that certain Indexes and Files are available, which shouldn't be. I will be using dummy names.
You were able to access example.com/intern before, but I changed a line in /etc/apache2/apache2.conf according to this https://stackoverflow.com/a/31445273 . This worked partly, as I get a 403-Forbidden when I now navigate to example.com/intern and that's basically what I want.
However the directory intern governs a file called file.php.bak aswell as file.php. When I navigate to example.com/intern/file.php I get a white website. I am however not sure, if you are able to access file.php in another way, because the site does load and I don't get a 403 like before. What is way worse and the reason I am struggling with this is: If I go to example.com/intern/file.php.bak then my Browser (Firefox) offers me to download file.php.bak, which I can read in plaintext. I want all files in intern to not be accessible via the website, but I have no idea how to do this. Can anybody help?
Things I've tried:
Removing the Indexes from the apache2.conf file like mentioned above. It only puts the 403 on the directory itself and not recursively for all the files in it.
Writing a .htaccess file as described here: https://fedingo.com/how-to-prevent-direct-file-download-in-apache-server/ and putting it in intern with the same result as in 1)
Putting an empty index.html file in the intern directory. This leads to no more 403 in example.com/intern, but the download on example.com/intern/file.php.bak is still possible. I've also tried index.php with the same result.
File System:
The application runs from /var/www/application which is also the folder for the /var/www/application/index.php I want to use. The /var/www/application/intern directory is also there. While it isn't browsable anymore, the files in it still are accessible. /var/www/application/intern/file.php can be navigated to via example.com/intern/file.php, but it seems like it can't be downloaded or read as it results in a white page. /var/www/application/intern/file.php.bak can however be downloaded via example.com/intern/file.php.bak.
Let's say Apache document root is set to DocumentRoot "/folder_one/folder_two"
Placing files in a folder_one will prevent people browsing your apache server and requesting the files directly.
Place index file in folder_two and include some code such as PHP to tell apache to include whatever files you want from folder_one.
In this manor Apache will still be able to serve whatever files you want from folder_one and people will not be able to request the files directly as the are located in a directory above the Apache document root.
I have a generic site in /var/www/ and I did put my webpages in html, including sub folder that I am planning to use to store pdf and doc files.
Now; I would like that when a user go to mysite/files/docs or mysite/files/pdf, they can see the list of files, but even if they click on the parent link on that page, or if they type the url (like mysite/files); they won't see the list.
Is possible to enable the file display feature but only for certain folders? I did check Apache manual and it has options to set in httpd.conf file, although it was not really showing how to turn on or off specific folders; just how to turn it on and off globally.
I have .htaccess files that I use for settings, but even in that case; I can't find a way to display only some folder content and not others.
Create a .htaccess file in each directory files/docs and files/pdf
Then inside each .htaccess file add
Options +Indexes
That's it. It will display the files of only those 2 directories.
With Apache it is possible to have the settings such that when a user requests access to a directory and that directory does not contain any index file then Apache displays a default directory listing as shown in the attached image.
Can anybody tell me where that default directory listing file resides? I would like to modify it for responsive design as well as adding Google analytics code.
I am getting responsive design warnings from Google Webmaster tools on the WordPress uploads directories. I don't want to block them but in fact would like search engines to crawl and index them. With that being said, I also don't want to get mobile usability errors on the same.
The best way is to use the .htaccess file to gain control over directory listings with Apache. This website has a bunch of good stuff to look through: https://perishablepress.com/better-default-directory-views-with-htaccess/
Generally, I would recommend specifically creating index.html files or something to specifically control what users/search engines are seeing, but obviously modifying the default directory listing has benefits.
You can use HeaderName and ReadmeName to supply customised HTML for the header and footer of the directory listings:
# SPECIFY HEADER FILE
HeaderName header.html
# SPECIFY FOOTER FILE
ReadmeName footer.html
Note: Be sure to also set IndexOptions +SuppressHTMLPreamble if you are specifying a custom header & footer to stop Apache adding the default <html>, <head> and <body> elements!
There isn't a file per se. The HTML is embedded in the C source code for mod_autoindex.
You can't achieve some limited control over the output with the mod_autoindex configuration options, most useful of which will probably be the HeaderName Directive
HeaderName /path/to/index_header.html
… but if you want serious control over the output, then you are probably looking at writing your own server side program to replace mod_autoindex.
I just wanted to add a simple index.html to www re-direct command in an .htaccess file
When I opened the existing .htaccess file, the 'Options -Indexes' command was already in there. What exactly is this command? What is it instructing the search engines etc. to do?
Not a programmer, just an SEO manager. Thanks much, MB
The Indexes option sets whether you can "browse" the directory or not. If indexes is set to plus, and the directory has no index.html or index.php (of whatever) file, it will show the contents of the directory just like your filemanager would do. So if there are ten images in there, it simply shows them as a list with links to the actual image. You can click them and open them.
How do I customize the list that web server does in absence of index.* file in the web root or its child directory, if we do not put any index files in the web root directory and the directory has the read permission?
you can set the page to show for a directory url with the index directive, it doesn't need to point to something called index.*, might just as well be whatever.html. See http://nginx.org/en/docs/http/ngx_http_index_module.html#index for details
or you can set autoindex on to give a generated file/directory listing, you can use the autoindex_exact_size and autoindex_localtime to further customize that listing. See http://nginx.org/en/docs/http/ngx_http_autoindex_module.html for details
3th option, if your nginx is compiled with it, is the random_index, see http://nginx.org/en/docs/http/ngx_http_random_index_module.html for details.
NOTE: to find out if your nginx is compiled with the needed --with-http_random_index_module option use the command nginx -V
Well, it depends on what webserver you are using.
In case of Apache, direcory indexes handled by a module called mod_autoindex.
When you want to customize the directory listing, then you have to know that Apache need three 'view' files:
The Header — by default automatically generated by Apache The
Directory Listing — necessarily generated by Apache
The Footer — referred to as the “Readme” file
The Header and Footer parts are basically written in plain HTML. The directory listing is generated by Apache but you can apply CSS on it..
The whole thing is a rather long story, so what I can suggest is a well written article with the details about this 'directory listing customisation':
Better Default Directory Views with .htaccess