【问题标题】:index.php downloading rather than loadingindex.php 下载而不是加载
【发布时间】:2021-01-21 15:43:57
【问题描述】:

我是编码新手,如果有简单的解决方案,请见谅。

我刚刚尝试使用 FTP 传输一个全新的网站以替换旧版本,但是当尝试加载 index.php 页面时,它会下载该页面而不是加载它。我需要在我的 .htaccess 文件中添加什么来阻止这种情况发生吗?还是我错过了其他元素?

这是我当前的 .htaccess 文件;

<IfModule mod_deflate.c>

AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype

# For Olders Browsers Which Can't Handle Compression

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

#One year for image files

<filesMatch ".(jpg|jpeg|png|gif|ico|webp)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>

#One month for css and js

<filesMatch ".(css|js|woff2)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>

<IfModule mod_setenvif.c>
#Vary: Accept for all the requests to jpeg and png
  SetEnvIf Request_URI "\.(jpe?g|png)$" REQUEST_image
</IfModule>



<IfModule mod_rewrite.c>

  RewriteEngine On
  # Check if browser supports WebP images
  RewriteCond %{HTTP_ACCEPT} image/webp

  # Check if WebP replacement image exists
  RewriteCond %{DOCUMENT_ROOT}/$1.webp -f

  # Serve WebP image instead
  RewriteRule (.+)\.(jpe?g|png)$ $1.webp [T=image/webp]
</IfModule>

<IfModule mod_headers.c>
  Header append Vary Accept env=REQUEST_image
</IfModule>

<IfModule mod_mime.c>
  AddType image/webp .webp
</IfModule>

RewriteEngine On 
RewriteBase /

# Force SSL
RewriteCond %{SERVER_PORT} ^80$
RewriteRule (.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

ErrorDocument 404 /index.php

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

【问题讨论】:

  • AddHandler application/x-httpd-ea-php56 .php .php5 .phtml危险 PHP 5.6 has been End Of Life for over a year。它没有得到安全修复。不要使用它。 (如果您遇到的问题是由未安装 PHP 5.6 的服务器引起的,我不会感到惊讶)。
  • 刚刚检查了我的 cpanel 似乎我有一个新的 php 正在运行。如果我的服务器运行的是 7.0.33,我会将其更改为什么?
  • “它下载页面而不是加载它”实际上是什么意思?是下载的index.php文件中的代码还是里面的代码解释的结果
  • 页面是白色的,只是在下载index.php源代码。我已经通过 FTP 单独传输了文件,现在似乎可以正常工作了,这很奇怪

标签: html apache .htaccess


【解决方案1】:

这通常是由于处理程序代码不正确造成的。在 .htaccess 文件中,您需要确保处理程序代码与您的 php 版本匹配。如果没有,php 文件可能会尝试下载而不是处理。要在服务器上使用默认的 php 版本,请使用以下代码:

# Use system PHP5 as default
AddHandler application/x-httpd-php5 .php
You may also specify different php versions, depending on your need:
# Use system PHP5.2 as default
AddHandler application/x-httpd-php52 .php
# Use system PHP5.3 as default
AddHandler application/x-httpd-php53.php
# Use system PHP5.4 as default
AddHandler application/x-httpd-php54 .php
# Use system PHP5.5 as default
AddHandler application/x-httpd-php55 .php

还可以查看这个论坛,人们分享他们如何解决同样的问题:https://serverfault.com/questions/215455/what-causes-php-pages-to-consistently-download-instead-of-running-normally

【讨论】:

  • 感谢您的回复。我刚刚检查了我的 cpanel,我正在运行 php 7.0.33。我可以把它写成 AddHandler application/x-httpd-php7 .php 吗?
  • 是的,试试 AddHandler application/x-httpd-php7 .php 或 AddHandler application/x-httpd-php70 .php
猜你喜欢
  • 2013-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-07
  • 1970-01-01
  • 1970-01-01
  • 2011-01-23
  • 1970-01-01
相关资源
最近更新 更多