• Since the past day or so, WordPress has started mangling my root .htaccess file. As a result, I’ve been getting 500 server errors because it’s overwriting some bits, and hence ending up with incorrect statements.

    Has anybody else experienced this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Phil

    (@owendevelopment)

    Make sure anything you’ve custom-added to the the htaccess file is OUTSIDE of:

    # 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>
    # END WordPress

    Anything inside this can be overwritten by WordPress

    Thread Starter SecGen

    (@secgen)

    Hi Phil,

    Thanks for the prompt reply. My custom directives are indeed outside the WordPress BEGIN and END tags. It also doesn’t seem to make a difference if I put mine above or below.

    I’ve just recreated a .htaccess from scratch, and WordPress re-added its stuff at the end of the file. I’ll keep an eye on it to see if it changes again.

    Phil

    (@owendevelopment)

    Sure. Do not underestimate the power of htaccess – it can destroy worlds. ??

    Thread Starter SecGen

    (@secgen)

    It just happened again…

    WordPress had its stuff at the bottom, and now its gone and written it AGAIN at the top, overwriting a bunch of my lines in the process:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILEAddOutputFilterByType DEFLATE text/css
    AddOutputFilt# END WordPress
     text/x-js
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-httpd-php
    AddOutputFilterByType DEFLATE application/x-httpd-fastphp
    AddOutputFilterByType DEFLATE image/svg+xml
    </IfModule>
    
    # Add WWW to URL
    <IfModule mod_rewrite.c>
    RewriteEngine on
    
    RewriteCond %{SERVER_PORT} ^80$
    RewriteCond %{http_host} ^domain.com [nc]
    RewriteRule .? https://www.domain.com%{REQUEST_URI} [R=301,L]
    
    RewriteCond %{SERVER_PORT} ^443$
    RewriteCond %{http_host} ^domain.com [nc]
    RewriteRule .? https://www.domain.com%{REQUEST_URI} [R=301,L]
    </IfModule>
    
    # Options
    Options -Indexes
    Options +FollowSymlinks
    
    # 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>
    
    # END WordPress

    WTF.

    Phil

    (@owendevelopment)

    How bizarre…

    Try adding your working one back in there and locking it down so it can’t be changed, ie, chmod 644.

    Worth a go.

    I’ve just experienced this as well. In fact, my htaccess file is a disaster. There are numerous instances of #BEGIN WordPress and in some cases, it overwrote only part of the WordPress section. My client was merely making edits to some page content. One second it worked, then suddenly she got an Internal Server Error. Take a look below. Note that there is no #END W3TC Page Cache core. It was overwritten. Then after the first #END WordPress, you see the truncated portion of a duplicate WordPress section. This is what was causing the Internal Server Error I presume…(the line that starts with the partial URL)

    This is the second time this has happened to this site. The first time, W3 Total Cache was NOT installed, and I figured it was an aberration. However, I need to identify the cause of this problem to prevent it in the future. I guess I will chmod 644 for now, but that seems it would decrease functionality for the future. Any ideas why this is happening and how to prevent? Thanks.

    [UPDATE: I just discovered that the new .htaccess file is already set to 644. Should I set it to 444, thereby disabling the last of the ‘write’ abilities for user?]

    # BEGIN W3TC Browser Cache
    <IfModule mod_deflate.c>
        <IfModule mod_headers.c>
            Header append Vary User-Agent env=!dont-vary
        </IfModule>
            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>
    # END W3TC Browser Cache
    # BEGIN W3TC Page Cache core
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{HTTPS} =on
        RewriteRule .* - [E=W3TC_SSL:_ssl]
        RewriteCond %{SERVER_PORT} =443
        RewriteRule .* - [E=W3TC_SSL:_ssl]
        RewriteCond %{HTTP:Accept-Encoding} gzip
        RewriteRule .* - [E=W3TC_ENC:_gzip]
        RewriteCond %{REQUEST_METHOD} !=POST
        RewriteCond %{QUERY_STRING} =""
        RewriteCond %{REQUEST_URI} \/$
        RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
    
    # BEGIN WordPress
    
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule ^downloads([^/]+)$ https://www.wvup.dreamhosters.com/wp-content/plugins/download-monitor/download.php?id=$1 [L]
    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    reamhosters.com/wp-content/plugins/download-monitor/download.php?id=$1 [L]
    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    # BEGIN WordPress
    
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule ^downloads([^/]+)$ https://www.wvup.dreamhosters.com/wp-content/plugins/download-monitor/download.php?id=$1 [L]
    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WordPress mangling htaccess file (500 server error)’ is closed to new replies.