' ; ?>

Hosting365

How to Stop WordPress From Overwriting .htaccess File

The way to Cease WordPress From Overwriting .htaccess File


Lately certainly one of our readers requested if it was attainable to cease WordPress from overwriting the customized code in your .htaccess file?

WordPress together with a number of plugins add customized settings to the .htaccess configuration file. In case you have added your individual customized code to .htaccess, then you could be anxious that it will likely be overwritten or deleted.

On this article, we’ll present you the right way to cease WordPress from overwriting the .htaccess file.

Why Does WordPress Overwrite the .htaccess File?

Your .htaccess file is a robust configuration file that shops necessary settings about your WordPress web site. It comprises guidelines that inform your internet hosting server the right way to deal with your web site.

WordPress makes use of the .htaccess file to retailer its permalink settings. Everytime you change or regenerate your permalinks, WordPress will routinely overwrite the outdated settings in .htaccess with the brand new settings.

Some WordPress plugins additionally save their settings in .htaccess. For instance, the W3 Whole Cache plugin will modify your .htaccess file with a purpose to configure the caching and optimization instruments which can be a part of the plugin.

Lastly, you can also make your individual customized modifications to .htacess to manage how your web site works. For instance, you’ll be able to add customized guidelines to the file that defend your admin space, hold your web site protected from hackers, arrange redirects, ban suspicious IP addresses, and extra.

Some customers are involved that in the event that they add their very own customized guidelines to .htaccess, then they could be deleted when WordPress overwrites the file with new settings. Different customers want to manually configure .htaccess and never let WordPress write to it in any respect.

With that being mentioned, let’s check out the right way to cease WordPress from overwriting your .htaccess file. Merely use the fast hyperlinks beneath to leap to the part you have an interest in.

The way to Cease WordPress From Overwriting Your .htaccess Guidelines

The excellent news is that when you perceive how the .htaccess file works, then you definitely may be assured that your customized guidelines won’t be overwritten.

That’s as a result of the areas of the file that shall be modified by WordPress or your plugins are clearly marked. Merely just be sure you don’t add code to these areas.

Don’t Modify Code Contained in the WordPress Markers

As we mentioned earlier, WordPress makes use of .htaccess to retailer the settings for an Web optimization-friendly URL construction. The code it saves to the file shall be routinely overwritten and up to date everytime you change your permalink settings.

As you’ll be able to see within the screenshot beneath, WordPress saves this data between two markers, # BEGIN WordPress and # END WordPress.

WordPress Markers in .htaccess

Discover the warning inside these markers:

The directives (traces) between “BEGIN WordPress” and “END WordPress” are dynamically generated, and may solely be modified by way of WordPress filters. Any modifications to the directives between these markers shall be overwritten.

Which means WordPress won’t overwrite or modify any code that you just add outdoors these markers. Customers sometimes add their customized code to the highest of the file, above the # BEGIN WordPress marker.

Don’t Modify Code Inside Your Plugins’ Markers

When a plugin saves its settings to .htaccess, it additionally locations it between markers that appear like # BEGIN Plugin and # END Plugin.

For instance, when you set up and arrange the W3 Whole Cache plugin to enhance your web site pace and efficiency, then it would add guidelines to .htaccess between # BEGIN W3TC Browser Cache and # END W3TC Browser Cache markers.

Example of Plugin Markers in .htaccess

These guidelines shall be overwritten everytime you change the plugin’s settings, so it is advisable to watch out to not add your individual customized .htaccess guidelines between these markers.

Creating Markers for Your Customized Code

In uncommon instances, a badly behaved plugin could modify code outdoors of its # BEGIN and # END markers. Nevertheless, it would usually not modify code discovered between the markers utilized by WordPress or different plugins.

In case you are involved a couple of badly behaved plugin overwriting your code, then you’ll be able to add your individual markers to the .htaccess file.

For instance, you’ll be able to sort # BEGIN MyCustomCode and # END MyCustomCode markers on the prime of the .htaccess file, after which add your individual customized guidelines between these markers.

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

In the event you additionally want so as to add code to the tip of .htaccess, then you’ll be able to add a unique set of markers there. Simply you should definitely give them completely different names. For instance, you can use ‘MyCustomCodeTop’ and ‘MyCustomCodeBottom’.

The way to Cease WordPress From Modifying .htaccess

Now that you just perceive how .htaccess works, you may be assured that your customized code won’t be overwritten by WordPress or your plugins.

Nevertheless, some builders and superior customers need to cease WordPress from making any modifications to .htaccess.

For instance, they could need to create permalinks by typing the settings manually into .htaccess. On this case, they may need to keep away from conflicts by stopping WordPress from saving its personal permalink settings to the file.

We don’t advocate this until what you’re doing, as a result of it could result in surprising penalties. Nevertheless, it may be achieved by altering the file’s permissions or utilizing code.

Stopping WordPress From Altering .htaccess Utilizing File Permissions

One solution to cease WordPress from modifying .htaccess is to make the file read-only. To do that, it is advisable to change the file permissions utilizing an FTP consumer or the file supervisor supplied by your WordPress internet hosting supplier.

You will see that the .htaccess file within the root listing of your WordPress set up. Subsequent, you need to right-click the file and choose ‘File permissions’.

Selecting File Permissions From the Menu in Your FTP Client

It will show a pop-up the place you’ll be able to change the file’s attributes.

The default setting shall be 644, however you’ll be able to change this to 444 by typing straight into the ‘Numeric worth’ discipline or ensuring that solely the ‘Learn’ packing containers are checked.

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

When you click on the ‘OK’ button, the file shall be read-only and can’t be modified.

In fact, this can imply that you’re unable to write down to the file as properly. If you want to make modifications, you will want to quickly set the file permissions again to 644.

Stopping WordPress From Altering .htaccess Utilizing Code

One other resolution is to make use of a code snippet that lets WordPress know to not write to the .htaccess file. That is helpful if you wish to cease WordPress from modifying .htaccess with out blocking your plugins.

Observe: Modifying any core WordPress recordsdata may be harmful. Even a small mistake may cause main errors in your web site. That’s why we solely advocate this methodology for superior customers.

Merely add the next code snippet on the finish of your wp-config.php file. In the event you need assistance, then please discuss with our information on the right way to edit the wp-config.php file in WordPress.

add_filter(‘got_rewrite’, ‘__return_false’);

When you’ve achieved that, WordPress will not write to the .htaccess file.

Error Message Displayed When WordPress Can’t Change .htaccess

In the event you attempt to change your permalink settings when .htaccess is ready to read-only, then an error message shall be displayed.

On the prime of the Settings » Permalinks web page, you will notice the message ‘You must replace your .htaccess file now.’

Permalink Settings Error Message When .htaccess Cannot Be Accessed

This allows you to know that WordPress was unable to switch the .htaccess file.

Usually, that is what you supposed. Nevertheless, when you do want to add the WordPress permalink settings to .htaccess, then you will want to do it manually.

On the backside of the Settings ≫ Permalinks web page, you will notice one other error message saying that your .htaccess file will not be writable. Beneath that, you will notice the foundations that should be added to .htaccess.

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

In the event you want to add these settings, then you will want to quickly change the .htaccess file permissions again to 644 in order that it may be edited. After that, you need to paste the foundations between the file’s WordPress BEGIN and END markers, changing the code already there.

If you’re completed, merely set the worth again to 444 and save the file. It’s going to as soon as once more be unwritable.

We hope this tutorial helped you discover ways to cease WordPress from overwriting the .htaccess file. You might also need to discover ways to add push notification in WordPress and take a look at our skilled checklist of the most effective WordPress Web optimization plugins and instruments.

In the event you favored this text, then please subscribe to our YouTube Channel for WordPress video tutorials. You too can discover us on Twitter and Fb.



Supply hyperlink

managed wordpress hosting

댓글 달기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

WP Twitter Auto Publish Powered By : XYZScripts.com
AI Chatbot Avatar