Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

html - index.php downloading rather than loading

I am new to coding so please forgive me if there is a simple solution.

I have just tried to transfer a brand new website to replace an older version using FTP, however when trying to load the index.php page, it downloads the page rather than loading it. Is there something I need to add to my .htaccess file to stop this happening? Or is there another element that I have missed?

This is my current .htaccess file;

<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 MSIE !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
question from:https://stackoverflow.com/questions/65830852/index-php-downloading-rather-than-loading

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is normally due to an improper handler code. In the .htaccess file, you will want to ensure the handler code matches your version of php. If it does not, the php files may try to download instead of process. To use the default php version on the server, use the following code:

# 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

Also check out this forum where people share how they resolved this same issue: https://serverfault.com/questions/215455/what-causes-php-pages-to-consistently-download-instead-of-running-normally


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...