0

If I open my URL http://example.com/, it shows my all sub directory like below

Index of /
•   data1.php 
•   data1.txt 

I want if any web user search like “http://example.com”, it will automatically forwarded the like http://example.com/data1.php. By this way I want to hide my all php, html or .text file form external web user.

7
  • 2
    You need to configure your web server. Commented Apr 22, 2013 at 14:59
  • You can disallow directly listings on your web server. Additionally, you can create a default page that will load in place of a directory listing. As for "hiding" your files, understand that if you make them inaccessible then, well, people won't be able to access them. Commented Apr 22, 2013 at 15:00
  • you could just rename data1.php to index.php Commented Apr 22, 2013 at 15:01
  • somehow I feel that telling you Options -Indexes wont be much of a help. As SLaks already stated, you need to configure your webserver. If its apache or iis or whatsoever, have a read into those options. Everything you want can be achieved with really tiny effort Commented Apr 22, 2013 at 15:01
  • 1
    @phpNoOb .htaccess is one way of configuring the web server. Commented Apr 22, 2013 at 15:01

2 Answers 2

5

You need to have a .htaccess file in the web root and just keep this as the first line

DirectoryIndex home.php

Also you can make changes in the your httpd.conf file

<IfModule dir_module>  #Keep adding pages here, it will read from left to right
    DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>

but you better stick to .htaccess instead


Not required but you might also like to deny directory listing you can use this

#Block Directory Listing
IndexIgnore *
Sign up to request clarification or add additional context in comments.

2 Comments

@nur2544 you welcome, if this has helped you, than mark the answer as correct :)
How can I test this? How can I try to access the files via browser?
0

If you have permission to edit the master configuration files

Edit the files httpd.conf and srm.conf file and do the following:

  • Find this line.

    DirectoryIndex index.html
    
  • Change it as follows:

    DirectoryIndex index.shtml index.html 
    

Of course, you can use any filename you wish. I prefer to leave index.html as a valid index as well.

Changing The Default Page using .htaccess

If you are unable to edit your master configuration files, you can use this directive from .htaccess. Just edit the .htaccess file located in your main HTML directory. If you do not have this file, feel free to create it!

To change the default page, either edit the existing DirectoryIndex line or add the following:

DirectoryIndex index.shtml index.html 

This will make index.shtml the default page.

By using a .htaccess file in a subdirectory, you can specify a different default page for that one directory without affecting the rest of your site.

Font: http://bignosebird.com/apache/a2.shtml

1 Comment

Hi Oswald, thanks for reply. i got your point, i will try to resolve my issue as you told.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.