【问题标题】:Server tries to download homepage - other pages/files display fine服务器尝试下载主页 - 其他页面/文件显示正常
【发布时间】:2013-02-07 03:24:53
【问题描述】:

在我们的 Linux 测试服务器上从 php 4 升级到 php 5 后,服务器现在会提示用户并在我们导航到 test.domain-name.org 时尝试下载主页。如果我专门指向索引文件,则没有问题,页面显示正常。仅当我们仅访问 test.domain-name.org 时才会出现问题。这会生成一个下载提示。如果我导航到特定于页面的 url,例如 test.domain-name.org/index.html 或 test.domain-name.org/index.php,页面加载正常。 Linux 人说他将服务器设置为与其他没有问题的服务器相同。作为 php 人,我回答说我的代码和 mod_rewrite 与我们其他没有问题的站点相同。我能够读取 phpinfo 文件。 Apache 版本是 2.2.23。 PHP 版本是 5.3.21。我读过其他帖子,但这个问题似乎与其他帖子不同。这是我的 htaccess 文件主页的 mod_rewrite 代码:

    RewriteRule ^/?(index.html)?$ index.php [L]

【问题讨论】:

  • 试试header("Content-Type:text/html; charset=YOUR-CHARSET')
  • 在 apache 检查:DirectoryIndex index.html index.cgi index.pl index.php index.xhtml
  • @Peter,谢谢,但它仍在提示下载。我将该代码放在将字符集定义为 utf-8 的 php 文件的顶部。

标签: php linux apache mod-rewrite


【解决方案1】:

在apache配置文件httpd.conf中检查DirectoryIndex

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents.  The MultiViews Option can be used for the
# same purpose, but it is much slower.
#
DirectoryIndex index.html index.html.var index.php 

conf 文件如下所示:

LoadModule php5_module /usr/lib/httpd/modules/libphp5.so
AddType application/x-httpd-php .php
DirectoryIndex index.php

确保您的 web 目录中的 .htaccess 文件中没有 IndexIgnore *

阅读它IndexIgnore

有用的链接 IndexIgnore * or Options -Indexes

【讨论】:

  • 同时检查主 Apache 配置是否允许覆盖索引。问题在于,如果没有文件名或斜杠,则会提供内容类型对 Web 服务器/浏览器未知的文件。
  • 你在 webroot 中有 .htaccess 文件吗?
  • 是的,有一个 htaccess 文件,我有点确定它在根目录中。另外,我有一个关于 DirectoryIndex 的问题。我们 httpd.conf 文件中的 DirectoryIndex 的文件扩展名比您上面列出的要多得多。如果我们将其限制为您在上面列出的三种不同的文件类型,这可能会结束下载提示吗?关于 conf,我现在正在尝试验证我们的是否包含您上面的内容。
  • 我会说删除 .htaccess 文件只是为了测试一下,看看会发生什么。还请阅读 stackoverflow.com/questions/14062641/…
  • @Satish,您对 .htaccess 的回答是正确的。我使用 IndexIgnore * 阅读了您推荐的帖子。我删除了 IndexIgnore * 并解决了问题。不再有下载提示。第二个 .htaccess 文件放置在子目录中。我猜想使用两个 .htaccess 文件和 IndexIgnore * 是造成问题的原因。如果您想更改答案,我会选择它作为接受的答案。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-27
  • 1970-01-01
  • 2017-09-04
相关资源
最近更新 更多