Search code examples
http-status-code-404wampwampserver

Display 'index of' page for images instead of 404 error


Using WAMP server (apache), if I put http://localhost:8080/website/img/ in the browser address bar and there is no index.html file in there I get an automated list of the linked (image) files in that directory:

Index of /website/img/

Parent Directory 
IMG1.jpg
IMG2.jpg
IMG3.jpg

This is using the default install of WAMP.

When I try the same thing on a remote site I have (hosted on GoDaddy w. Linux) I get a 404 (Page Not Found) Error, as you would expect I guess.

Is someone able to point me towards the way I can replicate the effect I get on my local machine on the remote site so the user is shown a similar crude list of images (or whatever) rather than a 404 error?

Thanks in advance.


Solution

  • it's because godaddy protect your folders by adding a .htaccess file inside them,if this file exists in your folder of img delete it and it will display the same thing as in localhost.

    Preventing Directory Listing

    Do you have a directory full of images or zips that you do not want people to be able to browse through? Typically a server is setup to prevent directory listing, but sometimes they are not. If not, become self-sufficient and fix it yourself:

    IndexIgnore * The * is a wildcard that matches all files, so if you stick that line into an htaccess file in your images directory, nothing in that directory will be allowed to be listed.

    On the other hand, what if you did want the directory contents to be listed, but only if they were HTML pages and not images? Simple says I:

    IndexIgnore *.gif *.jpg This would return a list of all files not ending in .jpg or .gif, but would still list .txt, .html, etc.

    And conversely, if your server is setup to prevent directory listing, but you want to list the directories by default, you could simply throw this into an htaccess file the directory you want displayed:

    Options +Indexes If you do use this option, be very careful that you do not put any unintentional or compromising files in this directory. And if you guessed it by the plus sign before Indexes, you can throw in a minus sign (Options -Indexes) to prevent directory listing entirely--this is typical of most server setups and is usually configured elsewhere in the apache server, but can be overridden through htaccess.

    If you really want to be tricky, using the +Indexes option, you can include a default description for the directory listing that is displayed when you use it by placing a file called HEADER in the same directory. The contents of this file will be printed out before the list of directory contents is listed. You can also specify a footer, though it is called README, by placing it in the same directory as the HEADER. The README file is printed out after the directory listing is printed.

    Read this :http://www.javascriptkit.com/howto/htaccess11.shtml