How to Fix “robots.txt file is not writable.” in Rank Math
The “robots.txt file is not writable” error in Rank Math usually means the plugin doesn’t have permission to modify your robots.txt file. This can be caused by a few different factors, so we’ll explore several potential solutions, starting with the most common scenario:
1. There is an Existing robots.txt File:
If you already have a robots.txt file in your website’s root directory, Rank Math might not be able to edit it directly. This is because WordPress plugins typically manage their own version of robots.txt, and having a pre-existing file can cause conflicts.
Solution:
- Locate the file: Use an FTP client (like FileZilla) or your hosting control panel’s file manager (e.g., cPanel) to access your website’s root directory.
- Delete (or rename): Either delete the existing robots.txt file entirely or rename it (e.g., to robots.txt.old) to temporarily disable it.
- Save changes: If you’re using an FTP client, ensure you save the changes and upload the modified directory structure to your server.
- Try Rank Math again: Go back to Rank Math’s robots.txt editor and see if you can now make changes.
Additional Considerations:
- Backup: Before deleting or renaming the original robots.txt file, make a copy of it just in case you need to restore it later.
- Custom directives: If the original robots.txt file contained important directives that you want to keep, make sure to add them back into Rank Math’s robots.txt editor after you’ve removed the old file.
- Advanced users: If you are comfortable working with code, you can also modify your website’s .htaccess file to redirect requests for robots.txt to the version generated by Rank Math.
If the “robots.txt file is not writable” error persists after removing the existing file, here are the other potential solutions:
Important Note: Always back up your website files before making any changes to the code or file permissions.
2. Granting Rank Math Permission to Edit:
Code Snippet: The most common solution is adding the following code snippet to your website:
/**
* Allow editing the robots.txt & htaccess data.
*
* @param bool Can edit the robots & htacess data.
*/
add_filter( 'rank_math/can_edit_file', '__return_true' );
Use code with caution.
- Where to Add: You can add this code snippet to your theme’s functions.php file or use a code snippets plugin.
- Explanation: This code essentially tells Rank Math that it’s allowed to edit both the robots.txt and .htaccess files.
3. Checking wp-config.php File:
DISALLOW_FILE_EDIT: In your wp-config.php file, look for the line:
define('DISALLOW_FILE_EDIT', true);
Use code with caution.
Change or Add: If you find this line, change it to:
define('DISALLOW_FILE_EDIT', false);
Use code with caution.
If the line doesn’t exist: add it with the value set to false. This enables file editing in WordPress, allowing Rank Math to make changes.
4. File Permissions:
- Check Permissions: Ensure that the robots.txt file has the correct permissions (usually 644). You can check this using your hosting control panel or an FTP client.
- Change Permissions: If the permissions are incorrect, you can change them using your hosting control panel or an FTP client.
- Contact Host: If you’re unable to change the permissions, contact your hosting provider for assistance.
5. Additional Tips:
- Disable Plugins: Temporarily disable other SEO plugins to see if they are conflicting with Rank Math.
- Contact Rank Math Support: If you’ve tried all these steps and the issue persists, reach out to Rank Math support for further assistance.
Leave a Reply