The best way to Prevent WordPress From Overwriting .htaccess Document

by | Feb 23, 2023 | Etcetera | 0 comments

In recent years regarded as considered one of our readers asked if it was once as soon as possible to forestall WordPress from overwriting the custom designed code to your .htaccess report?

WordPress in conjunction with numerous plugins add custom designed settings to the .htaccess configuration report. If you have added your personal custom designed code to .htaccess, then you’ll be able to be anxious that it’s going to be overwritten or deleted.

In this article, we’ll show you how to save you WordPress from overwriting the .htaccess report.

How to Stop WordPress From Overwriting .htaccess File

Why Does WordPress Overwrite the .htaccess File?

Your .htaccess report is a powerful configuration report that shops very important settings about your WordPress site. It comprises rules that tell your internet web hosting server how to deal with your website.

WordPress uses the .htaccess report to store its permalink settings. On each and every instance you exchange or regenerate your permalinks, WordPress will automatically overwrite the former settings in .htaccess with the new settings.

Some WordPress plugins moreover save their settings in .htaccess. For instance, the W3 Overall Cache plugin will alter your .htaccess report as a way to configure the caching and optimization apparatus which might be part of the plugin.

In spite of everything, you’ll make your personal customized adjustments to .htacess to keep watch over how your website online works. For instance, you’ll add custom designed rules to the report that give protection to your admin area, keep your website safe from hackers, organize redirects, ban suspicious IP addresses, and further.

Some consumers are concerned that within the match that they add their own custom designed rules to .htaccess, then they may be deleted when WordPress overwrites the report with new settings. Other consumers need to manually configure .htaccess and not let WordPress write to it the least bit.

With that being mentioned, let’s take a look at how to save you WordPress from overwriting your .htaccess report. Simply use the fast links underneath to jump to the section you are interested in.

The easiest way to Save you WordPress From Overwriting Your .htaccess Rules

The good news is that if you know how the .htaccess report works, then you definitely’ll be confident that your custom designed rules may not be overwritten.

That’s for the reason that areas of the report that will be changed thru WordPress or your plugins are patently marked. Simply make sure that you don’t add code to those areas.

See also  Construct a Tough MongoDB Copy Set in Document Time (4 Strategies)

Don’t Keep watch over Code Inside the WordPress Markers

As we mentioned earlier, WordPress uses .htaccess to store the settings for an Search engine optimization-friendly URL building. The code it saves to the report will be automatically overwritten and up to the moment every time you exchange your permalink settings.

As you’ll see throughout the screenshot underneath, WordPress saves this data between two markers, # BEGIN WordPress and # END WordPress.

WordPress Markers in .htaccess

Perceive the warning throughout the ones markers:

The directives (lines) between “BEGIN WordPress” and “END WordPress” are dynamically generated, and should only be modified by means of WordPress filters. Any changes to the directives between the ones markers will be overwritten.

This means that that WordPress isn’t going to overwrite or alter any code that you simply add outside the ones markers. Consumers maximum steadily add their custom designed code to the absolute best of the report, above the # BEGIN WordPress marker.

Tip: .htaccess is a hidden report positioned to your WordPress website’s root folder. For those who’re having difficulties finding it, then take a look at our knowledge on why you’ll’t to find the .htaccess document to your WordPress website online.

Don’t Keep watch over Code Inside of Your Plugins’ Markers

When a plugin saves its settings to .htaccess, it moreover places it between markers that appear to be # BEGIN Plugin and # END Plugin.

For instance, in the event you set up and arrange the W3 Overall Cache plugin to toughen your website online speed and serve as, then it’s going to add rules to .htaccess between # BEGIN W3TC Browser Cache and # END W3TC Browser Cache markers.

Example of Plugin Markers in .htaccess

The ones rules will be overwritten every time you exchange the plugin’s settings, so you need to be careful not to add your personal custom designed .htaccess rules between those markers.

Rising Markers for Your Custom designed Code

In unusual cases, a badly behaved plugin would perhaps alter code outside of its # BEGIN and # END markers. Alternatively, it’s going to most often not alter code found out between the markers used by WordPress or other plugins.

For those who’re fascinated about a badly behaved plugin overwriting your code, then you definitely’ll add your personal markers to the .htaccess report.

For instance, you’ll type # BEGIN MyCustomCode and # END MyCustomCode markers at the top of the .htaccess report, and then add your personal custom designed rules between those markers.

You Can Create Your Own Markers in .htaccess for Your Custom Rules

For those who occur to moreover wish to add code to the end of .htaccess, then you definitely’ll add a novel set of markers there. Merely remember to give them different names. For instance, that you simply should use ‘MyCustomCodeTop’ and ‘MyCustomCodeBottom’.

See also  How to Add WordPress Menus to Your Divi Footer

The easiest way to Save you WordPress From Enhancing .htaccess

Now that you know how .htaccess works, you’ll be confident that your custom designed code may not be overwritten thru WordPress or your plugins.

Alternatively, some developers and complicated consumers wish to save you WordPress from making any changes to .htaccess.

For instance, they’ll wish to create permalinks thru typing the settings manually into .htaccess. In this case, they’ll wish to avoid conflicts thru fighting WordPress from saving its non-public permalink settings to the report.

We don’t recommend this apart from you understand what you’re doing, as it’s going to finally end up in sudden consequences. Alternatively, it can be completed thru changing the report’s permissions or the usage of code.

Combating WordPress From Changing .htaccess Using File Permissions

One technique to save you WordPress from bettering .htaccess is to make the report read-only. To check out this, you need to change the report permissions the usage of an FTP consumer or the report manager provided thru your WordPress web hosting supplier.

You’ll to seek out the .htaccess report throughout the root list of your WordPress arrange. Next, you should right-click the report and choose ‘File permissions’.

Selecting File Permissions From the Menu in Your FTP Client

This will likely display a pop-up where you’ll alternate the document’s attributes.

The default atmosphere will be 644, alternatively you’ll exchange this to 444 thru typing right away into the ‘Numeric value’ field or making sure that only the ‘Be told’ packing containers are checked.

Changing the .htaccess File Permissions to 444 or Read-Only

For those who click on at the ‘OK’ button, the report will be read-only and will’t be modified.

In spite of everything, this will likely increasingly more indicate that you simply’re no longer in a position to write to the report as smartly. While you wish to have to make changes, it is very important temporarily set the report permissions once more to 644.

Combating WordPress From Changing .htaccess Using Code

Another solution is to use a code snippet that lets WordPress know not to write to the .htaccess report. This turns out to be useful if you want to save you WordPress from bettering .htaccess without blocking your plugins.

Phrase: Bettering any core WordPress files will also be dangerous. Even a small mistake may just motive major errors in your website. That’s why we only recommend this system for complicated consumers.

Simply add the following code snippet at the end of your wp-config.php report. If you want to have have the same opinion, then please discuss with our knowledge on the way to edit the wp-config.php document in WordPress.

add_filter('got_rewrite', '__return_false');

For those who’ve completed that, WordPress is not going to write to the .htaccess report.

See also  10+ Tutorials to Assist You Get Began with Divi Cloud

Error Message Displayed When WordPress Can’t Industry .htaccess

For those who occur to try to exchange your permalink settings when .htaccess is set to read-only, then an error message will be displayed.

At the top of the Settings » Permalinks internet web page, you’re going to see the message ‘You should substitute your .htaccess report now.’

Permalink Settings Error Message When .htaccess Cannot Be Accessed

This permits you to know that WordPress was once as soon as no longer in a position to change the .htaccess report.

In most cases, that’s what you meant. Alternatively, in the event you do wish to add the WordPress permalink settings to .htaccess, then it is very important do it manually.

At the bottom of the Settings ≫ Permalinks internet web page, you’re going to see each and every different error message announcing that your .htaccess report isn’t writable. Underneath that, you’re going to see the principles that wish to be added to .htaccess.

List of Rules You Will Need to Add to .htaccess Manually if Needed

If you wish to add those settings, then it is very important temporarily exchange the .htaccess report permissions once more to 644 so that it can be edited. After that, you should paste the principles between the report’s WordPress BEGIN and END markers, converting the code already there.

When you’re finished, simply set the cost once more to 444 and save the report. It’s going to once yet again be unwritable.

We hope this instructional helped you learn how to save you WordPress from overwriting the .htaccess report. You may also wish to be told the way to upload push notification in WordPress and check out our professional tick list of the most productive WordPress Search engine optimization plugins and equipment.

For those who occur to most popular this text, then please subscribe to our YouTube Channel for WordPress video tutorials. You’ll be capable to moreover to seek out us on Twitter and Fb.

The submit The best way to Prevent WordPress From Overwriting .htaccess Document first appeared on WPBeginner.

WordPress Maintenance

[ continue ]

WordPress Maintenance Plans | WordPress Hosting

read more


Submit a Comment

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