Apache 重写规则强制下载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/799649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache rewrite rule forces download
提问by Cruachan
I'm trying to port a PHP site developed by another coder (who is no longer around) and I'm having a problem with the Apache Rewrite rules which are prompting a file download on the target server. I'm sure this is a simple problem, but I'm having some difficulty Googling an answer. I'm running on a (dedicated) Ubuntu Server with a standard installation of Apache and PHP5 and porting from shared a shared server where everything runs fine. No site files have been altered during the port.
我正在尝试移植由另一个编码器(不再存在)开发的 PHP 站点,但我遇到了 Apache 重写规则的问题,该规则提示在目标服务器上下载文件。我确定这是一个简单的问题,但我在谷歌上搜索答案时遇到了一些困难。我在一个(专用)Ubuntu 服务器上运行,标准安装了 Apache 和 PHP5,并从共享服务器移植,在那里一切正常。在移植期间没有更改任何站点文件。
The .htaccess file contains this code (only)
.htaccess 文件包含此代码(仅)
# Use PHP5 as default AddHandler application/x-httpd-php5 .php Options -Indexes FollowSymlinks RewriteEngine on RewriteRule ^html/(.*) /index.php?init=site\/\/\/\/\/\/\/\/\/ RewriteRule ^mykart$ /index.php?admin=true RewriteRule ^mykart/$ /index.php?admin=true RewriteRule ^mykart/(.*)$ /index.php?init=admin\/\/\/\/\/\/\/\/\/&admin=true
When I try to open the file http://www.mysite.com/html/#homethe browser attempts to download the (index.php) file instead of displaying it, with the message
当我尝试打开文件http://www.mysite.com/html/#home 时,浏览器会尝试下载 (index.php) 文件而不是显示它,并显示消息
"You have chosen to Open [dialog shows blank space here]
“您已选择打开 [对话框在此处显示空白]
which is a: application/x-httpd-php from.... "
这是一个:application/x-httpd-php 来自....”
I guess I must have missed something in either the PHP or Apache configuration, but what?
我想我一定在 PHP 或 Apache 配置中遗漏了一些东西,但是什么?
EDIT: To clarify, the server is running Apache2 and has several, functioning, PHP sites on it. Furthermore if I delete the .htaccess file and run a simple phpinfo display page everything runs fine, so it's not the execution of PHP per see.
编辑:澄清一下,服务器正在运行 Apache2 并且上面有几个正常运行的 PHP 站点。此外,如果我删除 .htaccess 文件并运行一个简单的 phpinfo 显示页面,一切都运行良好,因此不是每次看到 PHP 的执行。
回答by Gumbo
I suppose that the MIME type application/x-httpd-php5is not valid. I've tried it on my local machine and it caused the same behavior.
我想 MIME 类型application/x-httpd-php5无效。我已经在我的本地机器上试过了,它导致了同样的行为。
Have you tried application/x-httpd-phpinstead?
你试过application/x-httpd-php吗?
回答by karim79
Looks like an Apache config issue, of course I could be wrong. Have you checked httpd.conf for the following lines:
看起来像是 Apache 配置问题,当然我可能是错的。您是否检查过 httpd.conf 中的以下几行:
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
AddType text/html php
回答by ivetame
I had a similar issue. Browser attempted to download links from php website, instead of loading them.
我有一个类似的问题。浏览器试图从 php 网站下载链接,而不是加载它们。
It wasn't Php interpreter issue for me, it turned out to be misplaced .htaccess file. However, I didn't realized that disabling the htaccess file solved the issue for hours, due to browser cache.
对我来说这不是 PHP 解释器问题,结果是放错了 .htaccess 文件。但是,由于浏览器缓存,我没有意识到禁用 htaccess 文件解决了这个问题几个小时。
So, don't forget to clear your browser caches! And restart Apache.
所以,不要忘记清除浏览器缓存!并重新启动Apache。

