Home  >  Article  >  Backend Development  >  How to Make Apache Serve index.php as the Default Page?

How to Make Apache Serve index.php as the Default Page?

DDD
DDDOriginal
2024-11-21 04:34:11692browse

How to Make Apache Serve index.php as the Default Page?

How to Load index.php by Default in Apache

If you encounter a "forbidden" error when accessing your website's root directory (e.g., http://example.com/myapp/) but can successfully access the index.php file directly (e.g., http://example.com/myapp/index.php), you may encounter an issue with how Apache handles index files.

To resolve this, Apache needs to be configured to recognize index.php as an index file. The simplest method is to create a .htaccess file in your web root with the following line:

DirectoryIndex index.php

This instructs Apache to treat index.php as an index file, making it the default page to load when the directory URL is accessed. Here's a detailed step-by-step guide:

  1. Create a .htaccess file in the web root of your website.
  2. Open the .htaccess file in a text editor.
  3. Add the following line: DirectoryIndex index.php
  4. Save and close the .htaccess file.

Note that Apache may need to be configured to allow .htaccess files (e.g., by enabling AllowOverride in httpd.conf).

The above is the detailed content of How to Make Apache Serve index.php as the Default Page?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn