My web server recognizes only index.html as the index file. Why? I want to use index.php because this way I can take advantage of all PHP features on the home page such as file includes. How can I do this without messing up anything?
This problem has a very simple solution. You just need to provide the appropriate instructions in the .htaccess file (that’s a period sign followed by htaccess). I am assuming you are running the Apache web server.
First we need to check if an .htaccess file exists. Connect to your web server and move to the document root. Hunt for the file – it’s generally the first one. Download it to the local computer and make a backup so that you can quickly restore it in case things go wrong.
Open the file in Notepad or any basic text editor and check if there is a line that starts with DirectoryIndex as in:
Change it to:
this tells Apache to use index.php as the index file for the main directories and all its subdirectories.
You can also modify the line as:
DirectoryIndex index.html index.php
But in this case, if a directory has both index.html and index.php, Apache will use the former as the index file. You can also change the order.
The .htaccess file can easily be created in Notepad or any basic text editor. Open a blank document and put in the following line:
Save the file as .htaccess and upload it to the document root.
That’s it; index.php will now work as the index on all directories.
Any file can be made to act as the index for Apache. You just need to specify its name in the DirectoryIndex command in the .htaccess file. Thus:
Please understand that the commands in .htaccess work for the directory is which the file is placed as well as all the subdirectories. Therefore, it’s a good practice to include more than one index file in DirectoryIndex. This tells Apache web server to fish out the second file in case the first one is missing. For instance,
DirectoryIndex openingpage.php index.php index.html
Apache will first try to load openingpage.php. If that is not present, the server will hunt for index.php and then index.html. If no files are found, Apache will throw up a 404 Page Not Found error.
The famous smiley was designed by Harvey Ball in 1963 to boost the morale of employees of Guarantee Mutual Company of Ohio. Ball, who was then a freelance artist, was paid $45 for his creation. [more...]