How to Fix WordPress Downloading Index.php Instead of Displaying Site

·

“WordPress downloads a compressed file instead of opening index.php or when i try to access my wp-admin”.

This was a question asked to us by one of our readers and he wanted to know how to solve it.

As I had no idea how was this happening I kept the question aside in my questions list until it happened with my blog.

This made me freak out as I lost access to my wp-admin, although I have a daily backup of my blog. But it’s not a choice to restore my blog as it’s a long list of work to be done and as for others, they don’t have a daily backup.

error establishing database connection

So just like a normal user I deactivated all my plugins through the backend of my hosting and tried to access the wp-admin, But this didn’t seem to work.

So I tried to restore my website theme to default twenty fifteen but this time too, I was out of luck and now I was worried.

I worked fine on my website all day yesterday, but this morning it tried to download the index.php instead of opening it like a browser normally does.

Now as I know I have tried:

  • Renaming my theme to old-[name-of-theme]
  • Renaming plugin folder to old-plugins (to disable them all)
  • Clearing the cache for Firefox, Safari, and Chrome.

Nothing worked.

I Googled and found some answers like

delete AddHandler application/x-httpd-php52 .php .php5 .php4 .php3
JavaScript

No idea how that got there! But I got my solution.

How to Fix WordPress Downloading Index.php Instead of Displaying Site - BloggerSprout

Disclosure: I may receive affiliate compensation for some of the links below at no cost to you if you decide to purchase a paid plan. You can read our affiliate disclosure in our privacy policy.

Method to Fix WordPress Downloading Index.php 

But here’s what I did It started working within 5 minutes and it was easy.
I accessed my .htaccess in cPanel and also kept a backup in case I messed up the config codes. (Please Keep a backup).

If for any reason you can’t find .htaccess on your WordPress installation root directory, then Click File Manager make sure to tick Show Hidden Files (dotfiles), and click Go.

The .htaccess should show up where wp (wp-admin, wp-content, wp-includes) is installed, which is your WordPress root directory.

I studied the code and I found some extra lines of code messing with my WordPress. I deleted the extra code and it started working.

For those who are not programmers for them follow the steps below:

  1. Open and edit .htaccess – Have a backup before editing
  2. Delete all the codes inside it
  3. Now copy the code below this and paste & save it
  4. It should be working now, you can access your WordPress admin.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST}//s%{HTTPS} ^www\.(.*)//((s)on|s.*)$ [NC]
RewriteRule ^ http%3://%1%{REQUEST_URI} [L,R=307]
AddType x-mapp-php5 .php

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]

# END WordPress
JavaScript




Hope this helps someone, and have a great day!!!

How to Fix WordPress Downloading Index.php Instead of Displaying Site - BloggerSprout

Click here to Download the ultimate guide to WordPress Errors and Solutions.

Conclusion

The reason why your index.php is downloaded is that of your caching plugin or feature in your host which adds a few lines of codes that make your WordPress fast as it compresses the file but in some cases, wp-admin is also cached which makes it impossible to access.

So just edit your .htaccess and paste the above code given and your blog is again ready to rock

If you have any queries, feel free to ask below in the comments. 

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

11 Comments

  1. Tech Bawaal says:

    Are you sure this code is legit, I mean when we go to WordPress.org and search htaccess it only shows basic coding?

    1. Niraj Kashyap says:

      Yes the code is legit. When you have a fresh copy of WordPress the .htaccess has only few lines. But after you install it, you will find that some more lines are automatically added by WordPress for Proper functioning.

      In this Problem, Every time you log into or access /wp-admin . It will download a file called index.php instead of the dashboard. This happens due to compressing of files by some caching plugin or server.

      This code overwrites everything to make wordpress work as normal like before.

      I hope this helps you, If your problem is solved by this method. Kindly let us know in the comments section.

      Thank you for your time and valuable feedback.

      Regards
      Niraj

      1. Tech Bawaal says:

        I had faced this problem many time but at the end, it solves automatically, but this it is happening again and again. I was using cache plugin for a long time I don’t think so it never occurs because of that but for making it clear, I deactivated it and I am still facing the same problem. It doesn’t happen frequently like continuing 2-3 days, it occurs for 15-20 mins then came back to normal state then the process continues.
        For eg. if I am login to my WordPress and doing something like I am in plugins area, then this issue happens suddenly without doing anything, and then when I click on something for eg I clicked on the customization tab it starts downloading customize-PHP file. Or I open my site it starts downloading a file called *download* with nothing in that. I have the latest version of PHP and everything is up to date. I almost 15 articles on this problem. Please help me out with the solution. Thanks

  2. Tech Bawaal says:

    Are you sure this code is legit, I mean when we go to WordPress.org and search htaccess it only shows basic coding?

    1. Niraj Kashyap says:

      Yes the code is legit. When you have a fresh copy of WordPress the .htaccess has only few lines. But after you install it, you will find that some more lines are automatically added by WordPress for Proper functioning.

      In this Problem, Every time you log into or access /wp-admin . It will download a file called index.php instead of the dashboard. This happens due to compressing of files by some caching plugin or server.

      This code overwrites everything to make wordpress work as normal like before.

      I hope this helps you, If your problem is solved by this method. Kindly let us know in the comments section.

      Thank you for your time and valuable feedback.

      Regards
      Niraj

      1. Tech Bawaal says:

        I had faced this problem many time but at the end, it solves automatically, but this it is happening again and again. I was using cache plugin for a long time I don’t think so it never occurs because of that but for making it clear, I deactivated it and I am still facing the same problem. It doesn’t happen frequently like continuing 2-3 days, it occurs for 15-20 mins then came back to normal state then the process continues.
        For eg. if I am login to my WordPress and doing something like I am in plugins area, then this issue happens suddenly without doing anything, and then when I click on something for eg I clicked on the customization tab it starts downloading customize-PHP file. Or I open my site it starts downloading a file called *download* with nothing in that. I have the latest version of PHP and everything is up to date. I almost 15 articles on this problem. Please help me out with the solution. Thanks

  3. Niraj this just worked for me, thanks my friend! I tried a few other fixes that I know of and nothing. Your fix got us back online thanks bunches!

  4. Niraj this just worked for me, thanks my friend! I tried a few other fixes that I know of and nothing. Your fix got us back online thanks bunches!

  5. i try this tipe but not work with me

    i change password Database and edit it in wp-config
    and remove all in htaccess file
    and add this only and it fixed
    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    1. Niraj Kashyap says:

      Yeah, thats the default .htaccess code

  6. That code worked well for me too. Finally can access my wp-admin properly. Thank you!