index.php默认不加载

001*_*001 103 php apache centos apache-config

我刚刚安装了CentOS,Apache和PHP.当我访问我的网站http://example.com/myapp/时,它会显示"禁止".默认情况下,它不加载index.php文件.

当我访问http://example.com/myapp/index.php时,它运行正常.

知道如何解决这个问题吗?

Joh*_*man 149

Apache需要配置为将index.php识别为索引文件.

完成这个的最简单方法..

  1. 在Web根目录中创建.htaccess文件.

  2. 添加行...

DirectoryIndex index.php

这是关于此事的资源......
http://www.twsc.biz/twsc_hosting_htaccess.php

编辑:我假设apache配置为允许.htaccess文件.如果不是,则必须修改apache配置文件(httpd.conf)中的设置

  • 它可能应该在apache加载的php.conf文件中. (4认同)
  • 不要忘记重新启动apache!!就像我一样!:/ (2认同)
  • 除非必要,最好的做法是永远不要使用“.htaccess”文件(即,如果您是共享托管环境中的用户,并且“.htaccess”是设置自定义配置选项的唯一方法,那么这是唯一的解决方案,但是当您具有管理访问权限时执行此操作会导致安全风险_并且_显着影响性能。如果您具有访问权限,则可以将相同的指令放入“httpd.conf”中。这样做也没有什么缺点;如果项目没有如果不使用 php,那么“index.php”文件无论如何都不存在。 (2认同)

M_M*_*M_M 97

将"DirectoryIndex index.php"添加到.htaccess文件可能有效,

注意:

通常,您不应该使用.htaccess文件

这是引自http://httpd.apache.org/docs/1.3/howto/htaccess.html
虽然这是指旧版本的apache,但我相信这个原则仍然适用.

将以下内容添加到httpd.conf(如果您有权访问它)被认为是更好的形式,导致更少的服务器开销并具有完全相同的效果:

<Directory /myapp>
DirectoryIndex index.php
</Directory>
Run Code Online (Sandbox Code Playgroud)

  • 如果你有权访问该文件,这一切都很好,花花公子 (4认同)

Ben*_*owe 42

猜测我会说目录索引设置为index.html,或者某些变体,请尝试:

DirectoryIndex index.html index.php
Run Code Online (Sandbox Code Playgroud)

这仍将使index.html优先于index.php(如果您需要抛出维护页面,则会很方便)


小智 13

这可能对某人有帮助.这是httpd.conf的片段(Apache 2.2版windows)

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
    DirectoryIndex index.php
</IfModule>
Run Code Online (Sandbox Code Playgroud)

现在这将寻找index.html文件,如果没有找到它将寻找index.php.

  • `DirectoryIndex index.html index.php`也可以 (2认同)