Lately considered one of our readers requested if it was once conceivable to prevent WordPress from overwriting the customized code on your .htaccess document?
WordPress together with a number of plugins upload customized settings to the .htaccess configuration document. You probably have added your individual customized code to .htaccess, then you can be fearful that it’s going to be overwritten or deleted.
On this article, we’ll display you the way to prevent WordPress from overwriting the .htaccess document.
Why Does WordPress Overwrite the .htaccess Document?
Your .htaccess document is a formidable configuration document that retail outlets essential settings about your WordPress site. It accommodates regulations that inform your web hosting server the way to maintain your website online.
WordPress makes use of the .htaccess document to retailer its permalink settings. On every occasion you convert or regenerate your permalinks, WordPress will robotically overwrite the previous settings in .htaccess with the brand new settings.
Some WordPress plugins additionally save their settings in .htaccess. As an example, the W3 Overall Cache plugin will adjust your .htaccess document with the intention to configure the caching and optimization equipment which are a part of the plugin.
Finally, you’ll make your individual customized adjustments to .htacess to keep an eye on how your site works. As an example, you’ll upload customized regulations to the document that offer protection to your admin house, stay your website online secure from hackers, arrange redirects, ban suspicious IP addresses, and extra.
Some customers are involved that in the event that they upload their very own customized regulations to .htaccess, then they could also be deleted when WordPress overwrites the document with new settings. Different customers wish to manually configure .htaccess and no longer let WordPress write to it in any respect.
With that being stated, let’s check out the way to prevent WordPress from overwriting your .htaccess document. Merely use the short hyperlinks under to leap to the phase you have an interest in.
The best way to Prevent WordPress From Overwriting Your .htaccess Laws
The excellent news is if you know the way the .htaccess document works, then you’ll be assured that your customized regulations is probably not overwritten.
That’s since the spaces of the document that will likely be modified through WordPress or your plugins are obviously marked. Merely just be sure you don’t upload code to these spaces.
Don’t Regulate Code Within the WordPress Markers
As we stated previous, WordPress makes use of .htaccess to retailer the settings for an Search engine optimization-friendly URL construction. The code it saves to the document will likely be robotically overwritten and up to date each time you convert your permalink settings.
As you’ll see within the screenshot under, WordPress saves this knowledge between two markers,
# BEGIN WordPress and
# END WordPress.
Understand the caution within the ones markers:
The directives (traces) between “BEGIN WordPress” and “END WordPress” are dynamically generated, and must solely be changed by way of WordPress filters. Any adjustments to the directives between those markers will likely be overwritten.
Which means that WordPress is not going to overwrite or adjust any code that you just upload outdoor those markers. Customers most often upload their customized code to the highest of the document, above the
# BEGIN WordPress marker.
Tip: .htaccess is a hidden document situated on your WordPress website online’s root folder. If you’re having difficulties discovering it, then check out our information on why you’ll’t to find the .htaccess document to your WordPress website online.
Don’t Regulate Code Within Your Plugins’ Markers
When a plugin saves its settings to .htaccess, it additionally puts it between markers that seem like
# BEGIN Plugin and
# END Plugin.
As an example, in case you set up and arrange the W3 Overall Cache plugin to give a boost to your site velocity and function, then it’s going to upload regulations to .htaccess between
# BEGIN W3TC Browser Cache and
# END W3TC Browser Cache markers.
Those regulations will likely be overwritten each time you convert the plugin’s settings, so you wish to have to watch out to not upload your individual customized .htaccess regulations between the ones markers.
Growing Markers for Your Customized Code
In uncommon instances, a badly behaved plugin would possibly adjust code outdoor of its
# BEGIN and
# END markers. Then again, it’s going to generally no longer adjust code discovered between the markers utilized by WordPress or different plugins.
If you’re interested in a badly behaved plugin overwriting your code, then you’ll upload your individual markers to the .htaccess document.
As an example, you’ll kind
# BEGIN MyCustomCode and
# END MyCustomCode markers on the most sensible of the .htaccess document, after which upload your individual customized regulations between the ones markers.
If you happen to additionally want to upload code to the tip of .htaccess, then you’ll upload a unique set of markers there. Simply make sure to give them other names. As an example, that you must use ‘MyCustomCodeTop’ and ‘MyCustomCodeBottom’.
The best way to Prevent WordPress From Editing .htaccess
Now that you know the way .htaccess works, you’ll be assured that your customized code is probably not overwritten through WordPress or your plugins.
Then again, some builders and complex customers need to prevent WordPress from making any adjustments to .htaccess.
As an example, they are going to need to create permalinks through typing the settings manually into .htaccess. On this case, they’ll need to steer clear of conflicts through preventing WordPress from saving its personal permalink settings to the document.
We don’t suggest this except you already know what you’re doing, as it may end up in surprising penalties. Then again, it may be accomplished through converting the document’s permissions or the use of code.
Preventing WordPress From Converting .htaccess The usage of Document Permissions
One option to prevent WordPress from enhancing .htaccess is to make the document read-only. To try this, you wish to have to modify the document permissions the use of an FTP consumer or the document supervisor supplied through your WordPress web hosting supplier.
You’ll to find the .htaccess document within the root listing of your WordPress set up. Subsequent, you must right-click the document and make a selection ‘Document permissions’.
This may show a pop-up the place you’ll alternate the document’s attributes.
The default surroundings will likely be 644, however you’ll alternate this to 444 through typing immediately into the ‘Numeric price’ box or ensuring that solely the ‘Learn’ containers are checked.
If you click on the ‘OK’ button, the document will likely be read-only and can’t be changed.
After all, this may increasingly imply that you’re not able to put in writing to the document as neatly. Whilst you want to make adjustments, it is important to quickly set the document permissions again to 644.
Preventing WordPress From Converting .htaccess The usage of Code
Any other resolution is to make use of a code snippet that shall we WordPress know to not write to the .htaccess document. This comes in handy if you wish to prevent WordPress from enhancing .htaccess with out blockading your plugins.
Word: Enhancing any core WordPress recordsdata may also be unhealthy. Even a small mistake could cause main mistakes to your website online. That’s why we solely suggest this technique for complex customers.
Merely upload the next code snippet on the finish of your wp-config.php document. If you wish to have lend a hand, then please confer with our information on the way to edit the wp-config.php document in WordPress.
If you’ve accomplished that, WordPress will not write to the .htaccess document.
Error Message Displayed When WordPress Can’t Trade .htaccess
If you happen to attempt to alternate your permalink settings when .htaccess is about to read-only, then an error message will likely be displayed.
On the most sensible of the Settings » Permalinks web page, you are going to see the message ‘You must replace your .htaccess document now.’
This allows you to know that WordPress was once not able to switch the .htaccess document.
Typically, that is what you supposed. Then again, in case you do want to upload the WordPress permalink settings to .htaccess, then it is important to do it manually.
On the backside of the Settings ≫ Permalinks web page, you are going to see every other error message pronouncing that your .htaccess document isn’t writable. Beneath that, you are going to see the foundations that want to be added to .htaccess.
If you want to upload the ones settings, then it is important to quickly alternate the .htaccess document permissions again to 644 in order that it may be edited. After that, you must paste the foundations between the document’s WordPress BEGIN and END markers, changing the code already there.
Whilst you’re completed, merely set the price again to 444 and save the document. It’s going to as soon as once more be unwritable.
We are hoping this educational helped you learn to prevent WordPress from overwriting the .htaccess document. You might also need to be informed the way to upload push notification in WordPress and take a look at our skilled checklist of the most productive WordPress Search engine optimization plugins and equipment.
If you happen to preferred this newsletter, then please subscribe to our YouTube Channel for WordPress video tutorials. You’ll be able to additionally to find us on Twitter and Fb.
The put up The best way to Prevent WordPress From Overwriting .htaccess Document first seemed on WPBeginner.WordPress Maintenance