Internal 500 Server Error After Activating W3 Total Cache WordPress Plugin

June 15th, 2013 - Posted by Steve Marks to PHP, Web Development.

If you’ve ever built, or are in the process of building, a site in WordPress I trust you’ve added a caching plugin. The increase in speed and reduction on server load is definitely worth it so, if you haven’t added one, I recommend you do go and do so now. Go on, I’ll wait for you here…

On my latest site I used the W3 Total Cache plugin. I added the files, activated it through the ‘Plugins’ page, and… uh oh… I immediately got presented with a ‘Server Error’ page. The error showed on all pages, both front end and back end, meaning I couldn’t access anything.

The Attempted Solution

My first thought was to remove the ‘w3-total-cache’ folder from the ‘/wp-content/plugins’ directory, effectively deactivating the plugin. This however didn’t work so I had to dig a little deeper.

The Real Solution

My next port of call was the apache error log. I opened up the logs and the last entry was as follows:

[Fri Jun 14 15:42:09.616166 2013] [core:alert] [pid 2684:tid 1652] [client ::1:55572] C:/xampp/htdocs/my-site/.htaccess: # without matching # section

As you can see, the error states that the problem lies in the .htaccess file of the site. After opening up the .htaccess file in question I could immediately see the problem. See if you can spot the problem below:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule># BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
<IfModule mod_mime.c>
# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
</IfModule>
</IfModule>
</IfModule>
# END W3TC Browser Cache

Can you see it? On line 8 you’ll notice that the W3 Total Cache plugin has added it’s own entries to the .htaccess upon being activated. This is great but it hasn’t added a line break and has just appended it to the end of the existing .htaccess content. We therefore end up with the following:

</IfModule># BEGIN W3TC Browser Cache

After adding the required line breaks the site then immediately became accessible again.

This entry was posted on Saturday, June 15th, 2013 at 9:43 am by +Steve Marks and is filed under PHP, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.
Comments...

Fear not, we won't publish this

Comments (11)
  1. Thank you brother. It really help me>>>>>>Thank you Very Much.

  2. Ashwin says:

    Perfect. This fixed it. :)

  3. Jorge says:

    Thank man you save my life!

  4. Zao says:

    Thanks so much for that tip! There were all these other things on forums that didn’t do a thing, but your solution is so simple and worked right away!

  5. Florian says:

    Thanks so much, dude! You’ve just saved me from doing tons of work :)!

  6. vkmaxx says:

    I was facing the same problem and I have final solved it by changing PHP version:
    http://www.maxxpreston.pl/web/internal-server-error-wordpress/

  7. @jonas – Simply add a line break (ie. a new line) on this line:

    RewriteRule . index.php [L]# BEGIN W3TC Browser Cache

    Before the hash (#).

  8. Hi,

    I got this problem and 500 international server error after activating w3 total cache, right now. And i am abit confused about how to fix it because my .htaccess file doesnt seem to be exact like yours.

    What do i need to edit to get it work again?
    My .htaccess file is following:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]

    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ – [L]
    RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]# BEGIN W3TC Browser Cache

    Header append Vary User-Agent env=!dont-vary

    AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json

    # DEFLATE by extension
    AddOutputFilter DEFLATE js css htm html xml

    # END W3TC Browser Cache


    I hope you will answer me, because i am scared as hell.

    Kind regards,
    Jonas Donbæk

  9. You saved my time :)

    thanks for this article…
    I really love it !!
    keep it up good work !! :)

  10. Wonderful, I was just about to delete it.

  11. Maurizio says:

    Thank you Steve,
    you have saved my day!

    I knew the problem was .htacces but didn’t see the missing line break.