Do I Have to Write Code in .htaccess for WP Ghost?

Moved

This tutorial has moved to the new WP Ghost Knowledge Base where each feature is presented in detail.

View on new site

No, in most cases WP Ghost writes the rewrite rules to .htaccess automatically when you save your settings. You do not need to edit any files manually. The only situation where manual editing is required is when your .htaccess file is not writable by the web server, which happens on some restrictive hosting environments. In that case, WP Ghost displays the rules for you to copy and paste.

How WP Ghost Handles .htaccess Automatically

When you activate Safe Mode or Ghost Mode and click Save, WP Ghost generates the necessary rewrite rules and writes them directly to the .htaccess file in your WordPress root directory. This is the same mechanism WordPress itself uses for permalinks. If your .htaccess file is writable (which it is on most hosting environments), the entire process is automatic and you never need to touch the file.

After saving, WP Ghost runs a Frontend Test to verify the rules are working correctly. If the test passes, everything is configured and no manual steps are needed.

When Manual Editing Is Required

On some hosting configurations, the .htaccess file is set to read-only or the web server process does not have permission to write to it. When this happens, WP Ghost detects the issue and displays the rewrite rules on screen after you save your settings. You then need to copy those rules and add them to your .htaccess file manually using FTP, your hosting’s File Manager, or SSH.

To add the rules manually, connect to your server via FTP or your hosting panel’s File Manager. Open the .htaccess file in the WordPress root directory. Paste the rules that WP Ghost displayed, placing them above the standard WordPress rewrite block (the section that starts with # BEGIN WordPress). Save the file and return to WP Ghost to verify the changes are working.

If you cannot access the server directly, you can ask your hosting provider to make the .htaccess file writable temporarily so WP Ghost can write the rules. After the configuration is saved, the file can be set back to read-only.

Alternative: Add Rules in WordPress Rewrite Block

If your hosting prevents any external .htaccess modifications but allows WordPress to manage its own rewrite block, WP Ghost has a fallback option. Go to WP Ghost > Advanced > Compatibility and enable Add Rewrites in WordPress Rules Section. This writes WP Ghost’s rules inside the WordPress rewrite block instead of outside it, which some hosting environments handle better. You can also set this via wp-config.php with define('HMW_RULES_IN_WP_RULES', true);. For Nginx servers, the process is different. See the Nginx Server Setup tutorial.

Frequently Asked Questions

How do I know if my .htaccess is writable?

If WP Ghost saves your settings without showing rewrite rules on screen, the file is writable and everything was written automatically. If WP Ghost displays a block of code after saving and asks you to add it manually, the file is not writable. You can also check the file permissions via FTP: the .htaccess file should be set to 644 for WordPress and WP Ghost to write to it.

Will editing .htaccess break my site?

If you paste the exact rules WP Ghost provides, no. Always make a backup of your .htaccess file before editing it manually. If something goes wrong, you can restore the backup via FTP to return to the previous state. If your site becomes inaccessible, removing the WP Ghost rules from .htaccess or renaming the file restores default WordPress behavior.

Does this apply to Nginx servers?

No. Nginx does not use .htaccess files. On Nginx, WP Ghost generates rules for the Nginx config file instead. You need access to the Nginx configuration to add these rules, or you can ask your hosting provider to add them. See the Nginx Server Setup tutorial for the full process.

Does WP Ghost modify WordPress core files?

No. WP Ghost only writes rewrite rules to .htaccess (Apache/LiteSpeed) or provides rules for the Nginx config. No WordPress core files, plugin files, or theme files are modified. Deactivating WP Ghost removes the rewrite rules and restores all defaults.