• We are on windows system and are experiencing an issue where wordpress keeps rewriting our htaccess file which causes us to loose customizations in the htacess.

    We would like to disable the ability of wordpress to do this. How can we do this? We have tried making the file read only but this did not help also if we make the authorized machine user not able to write to files we are not able to upload content, so that doesn’t work either.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The WordPress .htaccess section has two lines at the start and end, specifically # BEGIN WordPress and # END WordPress .

    Make sure that your .htaccess additions are being placed outside of these lines.

    Quoted this from James Huff on another similar question.

    An example would be.

    [custom stuff can go here]
    
    # 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
    
    [custom stuff can go here]
    Thread Starter neosin

    (@neosin)

    so if we remove # BEGIN WordPress # END WordPress it will stop changing the htaccess file?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    @neosin: No, if you do that then it will insert a new set of rules with a new BEGIN and END line.

    WordPress will only modify the lines between those BEGIN and END statements. If you have any custom rules for your site, make sure you put your rules outside of those two statements, and then WordPress will not modify it.

    @samuel Wood (Otto)

    Exactly, that’s pretty much it in a nutshell.

    Thread Starter neosin

    (@neosin)

    I understand.

    The problem we are having is that wordpress is randomly modifying our htaccess file. Both the code between the lines you mentioned and removing stuff outside of that.

    The ideal solution would be to disable the htaccess modification function entirely. Make it an optional ability that users can turn on and off.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Yeah, WordPress does not do that. It specifically reads in the .htaccess file and only modifies content in between those two markers.

    If you make the file read-only, WordPress will not modify it.

    I believe he said he tried that but I’d double check to make sure it is read-only, if not there has to be another solution, always is ??

    Just guessing on this one, but I think the implication might be that it isn’t WordPress itself that is making the modifications to the .htaccess file outside of the Begin and End statements (or inside, without user interaction). So… what is?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    WordPress specifically checks if both the home path and the .htaccess file in the home path are writable, using the PHP is_writable function. If it’s not writable (aka, read-only), WordPress does not attempt to write to it.

    If you’re on a Linux based hosting system, make the .htaccess file have 444 or 440 or 400 permissions. Use the smallest one that still works.

    Thread Starter neosin

    (@neosin)

    We use WPML to handle our site in two languages. There is a function in that plugin that enables rewriting the htaccess if you update you site language from one to the other. The problem is that we are not changing the sites language and yet the htaccess is being changed.

    This is our default working rewrite:

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

    this is sometimes what it changes it to:

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

    However this is not always the case, for example yesterday I added some rewrite rules outside of the # BEGIN # END to handle redirecting for old links to new locations. This morning the htaccess was missing those changes and yet the rest of the file was fine.

    truly bizarre situation

    If the plugin has re-write capability to edit your .htaccess file, I would get in touch with the plugin author to make sure there isn’t a bug or error causing this issue for you AFTER contacting your host and making sure everything is okay on their end first.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    If the WPML plugin is modifying the .htaccess file, and it’s not doing it in the correct way, then yes, WordPress may be overwriting its changes. Specifically, it will write the file whenever WordPress flushes the rewrite rules, which does happen on a regular basis.

    I would ask the WPML authors what is going on, and whether they can fix their plugin to behave correctly.

    For the specific case of the core WordPress permalinks, if you want it to not modify the file, then making the file read-only is the recommended solution. If you want to solve this from within a WordPress plugin, then this will work:

    add_filter('flush_rewrite_rules_hard','__return_false');

    This will prevent WordPress from *ever* writing the .htaccess or web.config files. However, note that if you do this, then permalinks may break if you change settings in the future, and that some plugins such as SEO or Cache plugins will be unable to write their rules to the file as well, meaning that they will randomly appear to not work properly.

    Disallowing .htaccess modification can cause breakage. It is far better to simply put your rules outside of the # BEGIN and # END lines, where they will be left alone by WordPress and by correctly functioning plugins.

    Thread Starter neosin

    (@neosin)

    thanks all for helping out

    WPML says they are looking to fix this issue in the next release

    You’re welcome, I’m glad they are working on a fix.

    In the meanwhile what Samuel suggested should work as a temporary fix so long as it doesn’t interfere with everything else he mentioned.

    Cheers.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Stop wordpress rewriting HTACCESS file ?’ is closed to new replies.