EDITS.WS

Tag: htaccess

  • How to Add HTTP Security Headers in WordPress (Beginner’s Guide)

    Do you want to add HTTP security headers in WordPress?

    HTTP security headers allow you to add an extra layer of security to your WordPress website. They can help block common malicious activity from affecting your site’s performance.

    In this beginner’s guide, we will show you how to add HTTP security headers in WordPress.

    How to Add HTTP Security Headers in WordPress (Beginner's Guide)

    What Are HTTP Security Headers?

    HTTP security headers are a security measure that allows your website’s server to prevent some common security threats before they can affect your website.

    When a user visits your WordPress website, your web server sends an HTTP header response to their browser. This response tells browsers about error codes, cache control, and other statuses.

    The normal header response issues a status called HTTP 200. After this, your website loads in the user’s browser. However, if your website is having difficulty, then your web server may send a different HTTP header.

    For example, it may send a 500 internal server error or a not found 404 error code.

    HTTP security headers are a subset of these headers. They are used to protect websites from common threats like click-jacking, cross-site scripting, brute force attacks, and more.

    Let’s have a quick look at some HTTP security headers and how they protect your website:

    • HTTP Strict Transport Security (HSTS) tells web browsers that your website uses HTTPS and should not be loaded using an insecure protocol like HTTP.
    • X-XSS Protection allows you to block cross-site scripting from loading.
    • X-Frame-Options prevents cross-domain iframes or click-jacking.
    • X-Content-Type-Options X-Content-Type-Options blocks content mime-type sniffing.

    HTTP security headers work best when they are set at the web server level, which means your WordPress hosting account. This allows them to be triggered early on during a typical HTTP request and provide maximum benefit.

    They work even better if you are using a DNS-level website application firewall like Sucuri or Cloudflare.

    That being said, let’s take a look at how to easily add HTTP security headers in WordPress. Here are quick links to different methods so that you can jump to the one that suits you:

    1. Adding HTTP Security Headers in WordPress Using Sucuri

    Sucuri is one of the best WordPress security plugins on the market. If you are using their website firewall service, then you can set HTTP security headers without writing any code.

    First, you will need to sign up for a Sucuri account. It is a paid service that comes with a server-level website firewall, security plugin, CDN, and malware removal guarantee.

    During sign-up, you will need to answer simple questions, and Sucuri documentation will help you set up the website application firewall on your website.

    After signing up, you must install and activate the free Sucuri plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

    Upon activation, you need to go to Sucuri Security » Firewall (WAF) and enter your Firewall API key. You can find this information under your account on the Sucuri website.

    Sucuri WAF API key

    After that, you will need to click the green ‘Save’ button to store your changes.

    Next, you must switch to your Sucuri account dashboard. From here, click on the ‘Settings’ menu on top and then switch to the ‘Security’ tab.

    Setting HTTP security headers in Sucuri

    From here, you can choose three sets of rules. The default protection will work well for most websites.

    If you have a Professional or Business plan, then you also have options for HSTS and HSTS Full. You can see which HTTP security headers will be applied for each set of rules.

    You need to click the ‘Save Changes in the Additional Headers’ button to apply your changes.

    Sucuri will now add your selected HTTP security headers in WordPress. Since it is a DNS-level WAF, your website traffic is protected from hackers even before they reach your website.

    2. Adding HTTP Security Headers in WordPress Using Cloudflare

    Cloudflare offers a basic free website firewall and CDN service. It lacks advanced security features in its free plan, so you will need to upgrade to its Pro plan, which is more expensive.

    You can learn how to add Cloudflare to your website by following our tutorial on how to set up the Cloudflare free CDN in WordPress.

    Once Cloudflare is active on your website, you must go to the SSL/TLS page in your Cloudflare account dashboard and then switch to the ‘Edge Certificates’ tab.

    Setting up HTTPS security headers in Cloudflare

    Now, scroll down to the ‘HTTP Strict Transport Security (HSTS)’ section.

    Once you find it, you need to click on the ‘Enable HSTS’ button.

    Click the Enable HSTS Button

    This will bring up a popup with instructions telling you that you must have HTTPS enabled on your website before using this feature.

    If your WordPress blog already has a secure HTTPS connection, then you can click on the ‘Next’ button to continue. You will see the options to add HTTP security headers.

    Enable HTTPS security headers in Cloudflare

    From here, you can enable HSTS, apply HSTS to subdomains (if the subdomains are using HTTPS), preload HSTS, and enable no-sniff header.

    This method provides basic protection using HTTP security headers. However, it does not let you add X-Frame-Options, and Cloudflare doesn’t have a user interface to do that.

    You can still do that by creating a script using the Cloudflare Workers feature. However, we don’t recommend this because creating an HTTPS security header script may cause unexpected issues for beginners.

    3. Adding HTTP Security Headers in WordPress Using .htaccess

    This method allows you to set the HTTP security headers in WordPress at the server level.

    It requires editing the .htaccess file on your website. This server configuration file is used by the most commonly used Apache webserver software.

    Note: Before making any changes to files on your website, we recommend making a backup.

    Next, simply connect to your website using an FTP client or the file manager in your hosting control panel. In the root folder of your website, you need to find the .htaccess file and edit it.

    View of Edit the .htaccess File Using an FTP Client

    This will open the file in a plain text editor. At the bottom of the file, you can add some code to add HTTPS security headers to your WordPress website.

    You can use the following sample code as a starting point. It sets the most commonly used HTTP security headers with optimal settings:

    <ifModule mod_headers.c>
    Header set Strict-Transport-Security "max-age=31536000" env=HTTPS
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Content-Type-Options nosniff
    Header set X-Frame-Options DENY
    Header set Referrer-Policy: no-referrer-when-downgrade
    </ifModule>
    

    Don’t forget to save your changes and visit your website to make sure that everything is working as expected.

    Note: Take care when editing code on your website. Incorrect headers or conflicts in the .htaccess file may trigger the 500 Internal Server Error.

    4. Adding HTTP Security Headers in WordPress Using AIOSEO

    All in One SEO (AIOSEO) is the best SEO tool for WordPress and is trusted by over 3 million businesses. The premium plugin lets you easily add HTTP security headers to your website.

    The first thing you will need to do is install and activate the AIOSEO plugin on your website. You can learn more in our step-by-step guide on how to set up All in One SEO for WordPress.

    You then need to head over to the All in One SEO » Redirects page to add the HTTP security headers. First, you will need to click the ‘Activate Redirects’ button to enable the feature.

    Activating Redirects in All in One SEO

    Once redirects are enabled, you need to click on the ‘Full Site Redirect’ tab and then scroll down to the ‘Canonical Settings’ section.

    Simply enable the ‘Canonical Settings’ toggle and then click the ‘Add Security Presets’ button.

    Add Security Presets in AIOSEO

    You will see a preset list of HTTP security headers appear in the table.

    These headers are optimized for security. You can review and change them if needed.

    Security Headers are Added in AIOSEO

    Make sure to click the ‘Save Changes’ button at the top or bottom of the screen to store the security headers.

    You can now visit your website to make sure that everything is working fine.

    How to Check HTTP Security Headers for a Website

    Now that you have added HTTP Security headers to your website, you can test your configuration using the free Security Headers tool.

    Simply enter your website URL and click on the ‘Scan’ button.

    Checking a Website's HTTP Security Headers

    It will then check HTTP security headers for your website and show you a report. The tool will also generate a so-called grade label, which you can ignore as most websites will get a B or C score without affecting user experience.

    It will show you which HTTP security headers are sent by your website and which ones are not included. If the security headers that you wanted to set up are listed there, then you are done.

    We hope this article helped you learn how to add HTTP security headers in WordPress. You may also want to see our complete WordPress security guide and our expert picks for the best WordPress plugins for business websites.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Add HTTP Security Headers in WordPress (Beginner’s Guide) first appeared on WPBeginner.

  • How to Fix the 500 Internal Server Error in WordPress

    Are you seeing a 500 internal server error in WordPress?

    The internal server error is one of the most common WordPress errors. Since the error doesn’t give any other information, many beginners find it quite frustrating.

    In this article, we will show you how to easily fix the 500 internal server error in WordPress.

    Fixing the internal server error in WordPress

    Here is a quick overview of the topics we’ll cover in this article.

    What is The 500 Internal Server Error?

    The 500 internal server error is a common web server error. It is not specific to WordPress websites and can happen with any website.

    The 500 in the error message is technically an HTTP error code. Looking up this code will only show its standard description.

    500 Internal Server Error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.

    This is a generic catch-all error message which means that the server was unable to assign a better more helpful error message when it encountered the issue.

    The error page looks different depending on which web server software (Nginx or Apache) your website is using and which browser you are using.

    Here is how the Apache error page may look.

    Internal server error page on Apache

    It may look different if you are using Nginx and Google Chrome.

    It will also look different if Google chrome is unable to find an error page to display:

    Google Chrome http 500 error

    For beginners, this can be incredibly frustrating. There is no clue or message that would point them in the right direction to quickly fix it.

    Asking how to fix an internal server error is like asking your doctor how to fix the pain you’re experiencing without telling them where the pain is.

    However, if we know the common causes that trigger this error, then we can try fixing them one by one to resolve the error without breaking anything.

    What Causes The Internal Server Error in WordPress?

    Internal server error in WordPress is often caused by a corrupt .htaccess file, poorly coded plugins, or your active WordPress theme.

    Other possible causes of the internal server error in WordPress that we know of are: PHP memory limit or corrupt core WordPress files.

    In some conditions, the internal server error may only show up when you are trying to access the WordPress admin area while the rest of the site works fine.

    That being said, now let’s take a look at how to go about troubleshooting the internal server error in WordPress.

    Video Tutorial

    If you prefer written instructions, then continue reading.

    Fixing The 500 Internal Server Error in WordPress

    Before you begin troubleshooting, make sure that you have a complete WordPress backup of your website on hand.

    If you have access to the WordPress admin area, then you can a WordPress backup plugin to create a complete backup of your website. We recommend using Duplicator to handle this.

    On the other hand, if you don’t have access to the WordPress admin area, then you can manually create a WordPress backup using phpMyAdmin and an FTP client.

    After that, you can follow the following steps to troubleshoot and fix the internal server error on your website.

    Clear WordPress and Browser Cache

    Browsers and your WordPress caching plugins can sometimes mistakenly store a cached copy of an error page.

    The easiest way to fix this is by first clearing your browser cache.

    Clear cache

    After that, if you have access to the WordPress admin area of your website, then you can empty the WordPress cache by visiting your caching plugin’s settings page.

    For details, see our tutorial on how to clear WordPress cache.

    Checking for Corrupt .htaccess File

    The .htaccess file is a server configuration file that is also used by WordPress to set up redirects.

    One of the most common causes of the internal server error is the corrupt .htaccess file.

    The easiest way to fix this is by simply visiting the Settings » Permalinks page in the WordPress admin area and then clicking on the ‘Save Changes’ button without making any changes at all.

    Update permalinks to regenerate .htaccess file

    WordPress will now try to update your .htaccess file or generate a new one for you. You can now visit your website to see if this has resolved the internal server error.

    If you can still see the error, then you need to make sure that WordPress was able to generate or write to the .htaccess file.

    Sometimes, due to file and directory permissions, WordPress may not be able to create or write to your .htaccess file.

    You can now try to manually replace the .htaccess file. First, you need to login to your website using FTP or the File Manager app under your hosting account control panel.

    Next, you need to rename your main .htaccess file to something like .htaccess_old. This lets you keep the file as a backup, but WordPress won’t recognize it.

    To rename the .htaccess file, you will need to login to your site using FTP or File Manager app in your hosting account’s cPanel dashboard.

    Once you are connected, the .htaccess file will be located in the same directory where you will see folders like wp-content, wp-admin, and wp-includes.

    Simply, right-click on the .htaccess file and rename it to .htaccess_old.

    Rename .htaccess file

    Next, you need to create a new .htaccess file.

    Inside your site’s root folder, right-click and then select ‘Create new file’ option in your FTP client or File Manager app.

    Create new htaccess file

    Name this new file .htaccess and click OK to save it.

    Now, this .htaccess file is currently empty and you need to add default WordPress rewrite rules to it.

    Simply right-click on the file and then select View/Edit in your FTP client or File Manager app.

    Editing .htaccess file in WordPress

    The empty file will open in a plain text editor like Notepad or TextEdit. Now, you need to copy and paste the following code inside it.

    # 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
    

    This code is the default rule set used by WordPress. Don’t forget to save your changes and upload the file back to the server.

    You can now visit your website to see if this has resolved the internal server error.

    If it did, then give yourself a pat on the back because you fixed the internal server error.

    Important: Before you move on with other things, make sure that you go to Settings » Permalinks page in the WordPress admin area and click the save button without making any changes. This will regenerate the .htaccess file for you with proper rewrite rules to ensure that your post pages do not return a 404 error.

    If checking for the corrupt .htaccess file solution did not work for you, then you need to continue reading this article.

    Increasing the PHP Memory Limit

    Sometimes the internal server error can happen if a script is consuming all the PHP memory limit.

    The easiest way to increase the PHP memory limit is by editing the wp-config.php file. Be careful when you do this if you’re a beginner. You want to follow these instructions carefully because even small mistakes in WordPress core files can break your site.

    To begin, simply connect to your WordPress website using an FTP client or the File Manager app under your hosting account control panel.

    You’ll find wp-config.php file inside the main folder of your website. Right-click on it and select ‘Download.’ This will ensure that you have a backup of the file in case something goes wrong.

    When you’ve saved that, you can right-click on it and select ‘View/Edit.’

    Edit wp-config file

    Inside the wp-config.php file, you need to add the following code just above the line that reads ‘That’s all, stop editing! Happy publishing’.

    define( 'WP_MEMORY_LIMIT', '256M' );
    

    For more details, see our tutorial on how to increase PHP memory limit in WordPress.

    If you are seeing the internal server error only when you try to log in to your WordPress admin or upload an image in your wp-admin, then you should increase the memory limit by following these steps:

    1. Create a blank text file on your computer and name it php.ini
    2. Paste this code in there: memory=256MB
    3. Save the file
    4. Upload it into your /wp-admin/ folder using FTP

    If increasing the memory limit fixed the problem for you, then you have only fixed the problem temporarily. You still need to find the cause that is exhausting your memory limit.

    This could be a poorly coded plugin or even a theme function. We strongly recommend that you ask your WordPress web hosting company to look into the server logs to help you find the exact diagnostics.

    If increasing the PHP memory limit did not fix the issue for you, then you are in for some more troubleshooting.

    Deactivate All WordPress Plugins

    If none of the above solutions worked for you, then this error is most likely being caused by a specific plugin installed on your website.

    It is also possible that it is a combination of plugins that are not playing nice with each other.

    If you can access the WordPress admin area of your website, then you can simply go to the plugins page and deactivate all WordPress plugins.

    Deactivate all plugins

    However, if you are unable to access the WordPress admin area, then you can deactivate all WordPress plugins using FTP.

    Simply connect to your WordPress website using an FTP client or the file manager app under your hosting account control panel.

    Once connected, navigated to the /wp-content/ folder and rename the plugins folder to plugins.deactivated.

    Plugins deactivated via FTP

    WordPress looks for plugins in the plugins folder. If the plugins folder is not found, then it will automatically deactivate all plugins.

    You can now try visiting your website to see if this resolved the internal server error on your website.

    To restore all your plugins, you can simply rename the plugins.deactivated folder back to plugins.

    Your plugins will now be restored but they will still be deactivated.

    You can now activate plugins one by one and visit your website to figure out which plugin is causing the internal server error.

    For more details, see our guide on how to deactivate all WordPress plugins without WP-Admin.

    If deactivating all plugins didn’t fix the internal server error on your website, then continue reading.

    Switch to a Default WordPress Theme

    One possible cause of the internal server error could be some code in your WordPress theme.

    To find out if this is the case, you need to switch your theme to a default WordPress theme.

    If you have access to the WordPress admin area, then simply go to the Appearance » Themes page. If you have a default theme already installed then you can simply click on the Activate button to switch theme.

    Activate a default theme

    If you don’t have a default theme installed, then you can click on the Add New button at the top and install a default theme (Twenty Twenty-Three, Twenty Twenty-Two, etc).

    Now in case you don’t have access to the WordPress admin area, you can still switch to a default theme.

    Simply, connect to your WordPress website using an FTP client and navigate to the /wp-content/ folder.

    Right-click to select the themes folder and download it to your computer as a backup.

    Download theme folder

    Next, you need to delete the themes folder from your website. Once it is deleted, go ahead and create a new themes folder.

    Your new themes folder will be completely empty which means you don’t have any WordPress themes installed at the moment.

    Next, you need to visit the WordPress themes directory and download a default WordPress theme to your computer.

    Download a default theme

    Your browser will then download the theme as a zip file to your computer.

    Locate the file on your computer and then unzip it. Windows users can unzip file by right-clicking on it and then selecting Extract All. Mac users can double-click on the zip file to extract it.

    Extract theme files

    You’ll now see a folder containing your WordPress theme.

    Switch back to your FTP client or File Manager up and upload this folder to the empty themes folder.

    Upload theme files

    Once uploaded, WordPress will automatically start using the default theme.

    You can now visit your website to see if this resolved the internal server error.

    If this didn’t work, then you can reupload your WordPress themes from the backup or switch back to the theme you were using.

    Don’t worry there are still a few more things you can do to fix the error.

    Re-uploading Core Files

    If the plugin and theme options didn’t fix the internal server error, then it is worth re-uploading the /wp-admin/ and /wp-includes/ folders from a fresh WordPress install.

    This will NOT remove any of your information, but it may solve the problem in case any file was corrupted.

    First, you will need to visit the WordPress.org website and click on the Download button.

    Download WordPress

    This will download the WordPress zip file to your computer.

    Go ahead and extract the zip file. Inside it, you will find a wordpress folder.

    WordPress folder extracted

    Next you need to connect to your WordPress website using an FTP client.

    Once connected go to the root folder of your website. It is the folder that has wp-admin, wp-includes, wp-content folders inside it.

    In the left column open the WordPress folder on your computer.

    Now you need to select all files inside the wordpresss folder and upload them to your website.

    Upload core WordPress files

    Your FTP client will now transfer those folders to your server.

    It will ask you whether you would like to overwrite the files. Select ‘Overwrite’ and then select ‘Always use this action’.

    Overwrite WordPress core files

    Your FTP client will now replace your older WordPress files with new, fresh copies.

    If your WordPress files were corrupted, then this step will fix the internal server error for you.

    Enable Debug Logs in WordPress

    WordPress comes with a built-in system to keep logs for debugging.

    You can turn it on by using the WP Debugging plugin. For more details, see our guide on how to install a WordPress plugin.

    Once activated, the plugin will turn on debugging logs on your WordPress website.

    If you don’t have access to the admin area of your WordPress website, then you can turn on debugging by adding the following code to your wp-config.php file.

    define( 'WP_DEBUG', true);
    define( 'WP_DEBUG_LOG', true); 
    

    Once you have turned on debug logs, you can view these logs by using an FTP client and navigating to the /wp-content/ folder.

    Debug log

    You can open the debug log file in a text editor and it will show you a list of errors and warnings that occur on your website.

    Some of these errors and warnings can be harmless incidents that may not need fixing. However, if you are seeing an internal server error on your website then these may point you in the right direction.

    Ask your Hosting Provider

    If all methods fail to fix the internal server error on your website, then it is time to get some more help. Contact your web hosting support team and they will be able to check the server logs and locate the root cause of the error.

    If you want to continue troubleshooting on your own, then see our ultimate WordPress troubleshooting guide for beginners.

    We hope this article helped you fix the internal server error in WordPress. You may also want to see our complete list of the most common WordPress errors, and our guide on how to choose the best web hosting provider.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Fix the 500 Internal Server Error in WordPress first appeared on WPBeginner.

  • How to Stop WordPress From Overwriting .htaccess File

    Recently one of our readers asked if it was possible to stop WordPress from overwriting the custom code in your .htaccess file?

    WordPress along with several plugins add custom settings to the .htaccess configuration file. If you have added your own custom code to .htaccess, then you may be worried that it will be overwritten or deleted.

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

    How to Stop WordPress From Overwriting .htaccess File

    Why Does WordPress Overwrite the .htaccess File?

    Your .htaccess file is a powerful configuration file that stores important settings about your WordPress website. It contains rules that tell your hosting server how to handle your site.

    WordPress uses the .htaccess file to store its permalink settings. Whenever you change or regenerate your permalinks, WordPress will automatically overwrite the old settings in .htaccess with the new settings.

    Some WordPress plugins also save their settings in .htaccess. For example, the W3 Total Cache plugin will modify your .htaccess file in order to configure the caching and optimization tools that are part of the plugin.

    Lastly, you can make your own custom changes to .htacess to control how your website works. For example, you can add custom rules to the file that protect your admin area, keep your site safe from hackers, set up redirects, ban suspicious IP addresses, and more.

    Some users are concerned that if they add their own custom rules to .htaccess, then they may be deleted when WordPress overwrites the file with new settings. Other users prefer to manually configure .htaccess and not let WordPress write to it at all.

    With that being said, let’s take a look at how to stop WordPress from overwriting your .htaccess file. Simply use the quick links below to jump to the section you are interested in.

    How to Stop WordPress From Overwriting Your .htaccess Rules

    The good news is that if you understand how the .htaccess file works, then you can be confident that your custom rules will not be overwritten.

    That’s because the areas of the file that will be changed by WordPress or your plugins are clearly marked. Simply make sure that you don’t add code to those areas.

    Don’t Modify Code Inside the WordPress Markers

    As we said earlier, WordPress uses .htaccess to store the settings for an SEO-friendly URL structure. The code it saves to the file will be automatically overwritten and updated whenever you change your permalink settings.

    As you can see in the screenshot below, WordPress saves this information between two markers, # BEGIN WordPress and # END WordPress.

    WordPress Markers in .htaccess

    Notice the warning inside those markers:

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

    This means that WordPress will not overwrite or modify any code that you add outside these markers. Users typically add their custom code to the top of the file, above the # BEGIN WordPress marker.

    Tip: .htaccess is a hidden file located in your WordPress site’s root folder. If you are having difficulties finding it, then take a look at our guide on why you can’t find the .htaccess file on your WordPress site.

    Don’t Modify Code Inside Your Plugins’ Markers

    When a plugin saves its settings to .htaccess, it also places it between markers that look like # BEGIN Plugin and # END Plugin.

    For example, if you install and set up the W3 Total Cache plugin to improve your website speed and performance, then it will add rules to .htaccess between # BEGIN W3TC Browser Cache and # END W3TC Browser Cache markers.

    Example of Plugin Markers in .htaccess

    These rules will be overwritten whenever you change the plugin’s settings, so you need to be careful not to add your own custom .htaccess rules between those markers.

    Creating Markers for Your Custom Code

    In rare cases, a badly behaved plugin may modify code outside of its # BEGIN and # END markers. However, it will normally not modify code found between the markers used by WordPress or other plugins.

    If you are concerned about a badly behaved plugin overwriting your code, then you can add your own markers to the .htaccess file.

    For example, you can type # BEGIN MyCustomCode and # END MyCustomCode markers at the top of the .htaccess file, and then add your own custom rules between those markers.

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

    If you also need to add code to the end of .htaccess, then you can add a different set of markers there. Just be sure to give them different names. For example, you could use ‘MyCustomCodeTop’ and ‘MyCustomCodeBottom’.

    How to Stop WordPress From Modifying .htaccess

    Now that you understand how .htaccess works, you can be confident that your custom code will not be overwritten by WordPress or your plugins.

    However, some developers and advanced users want to stop WordPress from making any changes to .htaccess.

    For example, they may want to create permalinks by typing the settings manually into .htaccess. In this case, they will want to avoid conflicts by stopping WordPress from saving its own permalink settings to the file.

    We don’t recommend this unless you know what you’re doing, because it can lead to unexpected consequences. However, it can be done by changing the file’s permissions or using code.

    Stopping WordPress From Changing .htaccess Using File Permissions

    One way to stop WordPress from modifying .htaccess is to make the file read-only. To do this, you need to change the file permissions using an FTP client or the file manager provided by your WordPress hosting provider.

    You will find the .htaccess file in the root directory of your WordPress installation. Next, you should right-click the file and select ‘File permissions’.

    Selecting File Permissions From the Menu in Your FTP Client

    This will display a pop-up where you can change the file’s attributes.

    The default setting will be 644, but you can change this to 444 by typing directly into the ‘Numeric value’ field or making sure that only the ‘Read’ boxes are checked.

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

    Once you click the ‘OK’ button, the file will be read-only and cannot be modified.

    Of course, this will mean that you are unable to write to the file as well. When you wish to make changes, you will need to temporarily set the file permissions back to 644.

    Stopping WordPress From Changing .htaccess Using Code

    Another solution is to use a code snippet that lets WordPress know not to write to the .htaccess file. This is useful if you want to stop WordPress from modifying .htaccess without blocking your plugins.

    Note: Editing any core WordPress files can be dangerous. Even a small mistake can cause major errors on your site. That’s why we only recommend this method for advanced users.

    Simply add the following code snippet at the end of your wp-config.php file. If you need help, then please refer to our guide on how to edit the wp-config.php file in WordPress.

    add_filter('got_rewrite', '__return_false');
    

    Once you’ve done that, WordPress will no longer write to the .htaccess file.

    Error Message Displayed When WordPress Can’t Change .htaccess

    If you try to change your permalink settings when .htaccess is set to read-only, then an error message will be displayed.

    At the top of the Settings » Permalinks page, you will see the message ‘You should update your .htaccess file now.’

    Permalink Settings Error Message When .htaccess Cannot Be Accessed

    This lets you know that WordPress was unable to modify the .htaccess file.

    Normally, this is what you intended. However, if you do wish to add the WordPress permalink settings to .htaccess, then you will need to do it manually.

    At the bottom of the Settings ≫ Permalinks page, you will see another error message saying that your .htaccess file is not writable. Underneath that, you will see the rules that need 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 you will need to temporarily change the .htaccess file permissions back to 644 so that it can be edited. After that, you should paste the rules between the file’s WordPress BEGIN and END markers, replacing the code already there.

    When you’re finished, simply set the value back to 444 and save the file. It will once again be unwritable.

    We hope this tutorial helped you learn how to stop WordPress from overwriting the .htaccess file. You may also want to learn how to add push notification in WordPress and check out our expert list of the best WordPress SEO plugins and tools.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Stop WordPress From Overwriting .htaccess File first appeared on WPBeginner.

  • How to Increase the Memory Limit in WordPress

    The post How to Increase the Memory Limit in WordPress is written by Tom Rankin and appeared first on WPKube.

    Almost everything in the world has a maximum capacity. Computers use a finite amount of memory to store routines, code, scripts, and much more. In some cases, you’ll want to boost this limit to stay away from errors. As for how to increase the memory limit within WordPress, you won’t be able to use the familiar dashboard screens. The main…. Continue Reading