Blog

A Guide to .htaccess Files for WordPress

Website Builder

Every WordPress website includes a .htaccess file, which stands for “hypertext access.” Most WordPress users won’t need to worry about it, as WordPress itself manages most of the settings. But if you need to do more advanced customisation like setting up redirects or password protection, then you might need to dip your toes into the .htaccess file. What is the .htaccess file for? The .htaccess file is a tool that allows you to make important changes to how your website functions without needing to modify the main server configuration. Think of .htaccess like a set of instructions for your website’s server. These instructions control how your site behaves and can be used to change various ways in which it all works. One of the most common uses for .htaccess is setting up URL redirects. Additionally, .htaccess allows you to password-protect certain parts of your website, adding an extra layer of security to sensitive content. You can also use it to create custom error pages, replacing the standard “Error 404” message with something more informative or visually appealing. Finally, .htaccess can be used to improve your website’s performance. By enabling compression, you can reduce the size of files sent to visitors’ browsers, making your site load faster and providing a better user experience. Where can I find my .htaccess file? You can find and edit your default WordPress .htaccess file by connecting to your site via FTP. Simply follow the instructions outlined below. Start by opening FileZilla. Once connected, your .htaccess file can be found below your main folders within the right-hand panel. To view it, simply right-click your .htaccess file and select. Your .htaccess file can be found below your main folders within the right-hand panel. To view it, simply right-click your .htaccess file and select View/Edit. If, however, you don’t see a .htaccess file within your folders, you will need to add one to your site. How do I add a .htaccess file? Although every WordPress site includes a .htaccess file, you can add multiple files to stipulate certain rules. Warning: Having multiple WordPress .htaccess files can affect your server’s performance so we recommend downloading a copy of your existing .htaccess file before getting started. To add a .htaccess file: Start by opening Notepad. Next, paste the following code and then save your document as .htaccess # BEGIN WordPressRewriteEngine OnRewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]RewriteBase /RewriteRule ^index.php$ – [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]# END WordPress Next, open FileZilla. Enter your FTP details into the provided fields and click Quickconnect. After you’ve connected to your site, right-click your .htaccess file within the left-hand menu and click Upload. Wrap up That’s it! In essence, the .htaccess file is a versatile tool that gives you control over your website’s functionality and performance, without needing to go deep into complex server settings. While most WordPress users won’t need to touch .htaccess file often (or at all), knowing where it is and what it does can be helpful for troubleshooting or making specific customisations. If you ever need to work with it, remember to proceed with caution and always have a backup ready.

Troubleshooting WordPress: How to Enable Debug Mode  

Website Builder

Debug mode is a special setting in WordPress that reveals detailed error messages and warnings that are typically hidden from view. These messages provide clues about what’s going wrong behind the scenes, helping you pinpoint and resolve any issues. Why enable debug mode in WordPress? Debug mode can reveal the root causes of errors, saving you the guesswork of trying to have to work out how and why they’re occurring. When it comes to optimising the speed and performance of your website, debugging is a way to uncover bottlenecks and resource-intensive processes that might be slowing everything down. Debug mode also gives you the chance to test out plugin and theme compatibility. It’s a smart way to see how new plugins and themes interact with your site and rat out any conflicts. While debug mode is a powerful tool, it’s not meant to be left permanently enabled on a live site. The detailed error messages it displays could potentially reveal sensitive information to visitors. However, it’s perfectly safe to temporarily enable debug mode for troubleshooting purposes and disable it again afterwards. In the next section, we’ll guide you through the simple steps to access and activate debug mode in your WordPress installation. How do I enable debug mode in WordPress? First, locate your wp-config.php file, typically found in the root directory of your WordPress installation. You can access it using an FTP client or your hosting provider’s file manager. Next, open the wp-config.php file in a text editor and search for the line define(‘WP_DEBUG’, false); Change false to true. Then, add the following code on the next line: define(‘WP_DEBUG_LOG’, true); This will create a log file to store error messages instead of displaying them directly on your website. After saving your changes to wp-config.php, visit your website in a browser. This will trigger WordPress to generate error logs. Once done, access the debug log file, named debug.log, which will be created in the /wp-content/ directory of your WordPress installation. Use your FTP client or file manager to access it. Finally, open the debug.log file in a text editor. You’ll see detailed error messages, warnings, and notices. Take a careful look at these to identify the source of your issue. The file paths mentioned in the errors can help you pinpoint whether a plugin, theme, or core file is causing the problem. Remember to turn debug mode off by changing WP_DEBUG and WP_DEBUG_LOG back to false in your wp-config.php file and delete the debug.log file once For more information on what each PHP error means, please read our Support article: Understanding WordPress related PHP errors What is the WordPress database connection string? The WordPress database connection string is a set of configuration values in the wp-config.php file. These values define how WordPress connects to its MySQL database. Occasionally, issues like the “Error Establishing a Database Connection” message might arise. This suggests a problem with how WordPress connects to its database. If this happens, you may need to update the connection strings in your wp-config.php file. How do I update my WordPress database connection string? Start by connecting to your hosting using an FTP client such as FileZilla. For details on how to do this, please read our Support article: How do I upload files using SFTP?  Once connected, locate the wp-config.php file, right-click on it, and select “Edit.” If prompted, choose a text editor like Notepad to open the file.  Inside the wp-config.php file, you’ll find lines defining your database name, username, password, and host. The section looks like this:  /** The name of the database for WordPress */ define(‘DB_NAME’, ‘yourdatabasename‘);  /** MySQL database username */ define(‘DB_USER’, ‘yourusername‘);  /** MySQL database password */ define(‘DB_PASSWORD’, ‘yourpassword‘);  /** MySQL hostname */ define(‘DB_HOST’, ‘yourhostname‘); $table_prefix  = ‘yourtableprefix‘;  Be sure to confirm that the information in this file matches your details:  yourdatabasename should match your MySQL Database Name yourusername should match your MySQL Username yourpassword should match your MySQL password yourhostname should match your MySQL Host Name yourtableprefix should match your Table Prefix  If any of the information within your wp-config.php file doesn’t match your database details, then update the file with the correct information. Save the updated file to confirm your changes. Be sure to check your website to make sure it’s back online.  Wrap Up And that’s it! You’ve learned how to use debug mode in WordPress. Remember: Debug is only a sort of “detective mode” for fixing problems. When you’re done fixing things, be sure to turn it off again. The messages it shows could give away secret information about your website. So, be careful and only use debug mode when you need to. This way, you can keep your WordPress website running smoothly and safely.