Use wp-config.php for WordPress application settings and secrets; use .htaccess for Apache request rules, redirects, and URL behavior. Mixing them up creates brittle sites, awkward fixes, and security gaps. WordPress is used by more than 43% of all websites tracked by W3Techs, so these two files sit at the center of a huge number of production sites [source: W3Techs].
TLDR: wp-config.php controls how WordPress connects, behaves, debugs, and protects sensitive values. .htaccess controls how the Apache web server handles requests before WordPress fully loads. For example, if a store owner wants to disable file editing after a contractor finishes work, that belongs in wp-config.php; if the same store needs all traffic forced from HTTP to HTTPS, that belongs in .htaccess. On a site with 50,000 monthly visits, a bad .htaccess redirect can affect every visitor instantly, while a bad database setting in wp-config.php can take the whole site offline.
What wp-config.php Actually Does
The wp-config.php file is the main configuration file for WordPress itself. It lives in the root WordPress directory, although it can sometimes be moved one level above the public web root for extra protection.
This file is loaded early. WordPress reads it before it connects to the database and before themes or plugins run. That makes it the right place for core constants, database credentials, and site level behavior.
- Database access: database name, username, password, host, and character set.
- Authentication salts: keys used to secure cookies and login sessions.
- Debug settings: values such as
WP_DEBUG,WP_DEBUG_LOG, andWP_DEBUG_DISPLAY. - Site URLs: constants like
WP_HOMEandWP_SITEURL. - Security controls: disabling theme and plugin file editing with
DISALLOW_FILE_EDIT. - Performance limits: memory limits, autosave timing, trash retention, and post revision limits.
- Multisite settings: network flags and domain mapping behavior.
Honestly, it feels like too many site owners only open this file when something is already broken. That is risky. A single misplaced quote can trigger a fatal error. A pasted smart quote from a document editor can waste 20 minutes for no good reason.
What .htaccess Actually Does
The .htaccess file is not a WordPress configuration file in the same sense. It is an Apache server configuration file placed inside a directory. Apache reads it when handling requests for that directory and its children.
WordPress uses .htaccess mainly for “pretty permalinks.” When someone visits /about/, Apache needs rules that pass the request to WordPress instead of looking for a physical folder named about. The standard rewrite block handles that.
Common .htaccess uses include:
- Permalink rewrite rules for WordPress posts, pages, and archives.
- HTTP to HTTPS redirects for secure traffic.
- www to non www redirects, or the reverse.
- Access restrictions for files such as
wp-config.phpor XML files. - Basic caching headers for static files.
- Blocking PHP execution in risky folders like
uploads. - IP based allow or deny rules for admin areas in some setups.
The catch is that .htaccess only works on Apache when overrides are allowed. If the server uses Nginx, LiteSpeed in certain modes, or managed hosting with custom routing, the same rules may need to live elsewhere. WordPress explains the basic permalink role of this file in its official documentation [source: WordPress].
The Practical Difference
wp-config.php answers this question: “How should WordPress run?”
.htaccess answers this question: “How should the web server handle this request?”
That distinction matters. If you want to stop admins from editing plugin files in the dashboard, use wp-config.php:
define( 'DISALLOW_FILE_EDIT', true );
If you want to redirect old URLs to new URLs, use .htaccess or your host’s redirect manager:
Redirect 301 /old-page/ https://example.com/new-page/
If you want to enable logging while fixing a plugin conflict, use wp-config.php:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
If you want to block direct access to a sensitive text file, .htaccess may be the right place:
<Files "private.txt">
Require all denied
</Files>
Security: Which File Is More Sensitive?
wp-config.php is usually more sensitive because it contains database credentials and authentication salts. If an attacker reads it, the damage can be severe. Database access may expose users, orders, posts, and private plugin data.
.htaccess is also critical, but in a different way. A weak or careless rule can expose files, break redirects, disable protections, or create redirect loops. It may not contain passwords, but it controls traffic.
Good security practice includes:
- Set file permissions carefully. Avoid making either file world writable.
- Do not store backups such as
wp-config.php.bakinside the public directory. - Keep credentials out of screenshots, support tickets, and public repositories.
- Use a staging site before changing rewrite rules on a busy site.
- Back up both files before edits.
Performance Impact
wp-config.php can affect performance through memory limits, caching constants, cron behavior, and environment flags. For example, disabling WordPress cron and replacing it with a real server cron can reduce random slow requests on high traffic sites.
.htaccess can also affect speed. Apache may check .htaccess files during request handling. Heavy rewrite logic and messy redirect chains add delay. One redirect may be fine. Five chained redirects are not fine. Expect to waste time on this when a migration leaves behind old plugin rules nobody remembers adding.
Clean rules help. Put plugin generated blocks where the plugin expects them. Keep custom rules documented. Remove dead redirects after migrations when they are no longer needed.
Common Mistakes
- Putting redirects in
wp-config.php: This loads WordPress when Apache could have handled the redirect sooner. - Putting WordPress constants in
.htaccess: Apache will not understand PHP constants. - Editing between plugin markers: Plugins may overwrite changes inside their own marked blocks.
- Leaving debug display on:
WP_DEBUG_DISPLAYshould usually be false on production sites. - Using copied rules blindly: A rule written for Apache 2.2 may fail on Apache 2.4.
- Forgetting the server type: Nginx does not use
.htaccess.
Which File Should You Edit First?
Start with the file that matches the problem.
- Database connection error? Check
wp-config.php. - White screen after enabling debug? Check
wp-config.php. - 404 errors after changing permalinks? Check
.htaccess. - Redirect loop? Check
.htaccess, SSL settings, and host level redirects. - Need to disable dashboard file editing? Use
wp-config.php. - Need to force HTTPS? Use host settings or
.htaccess, depending on the server.
A Safe Editing Workflow
Use a calm process. These files are small, but they can break a site fast.
- Download a fresh copy of the file before editing.
- Make one change at a time.
- Use a plain text code editor, not a word processor.
- Check the site in a private browser window.
- Check both the home page and one inner page.
- If the site fails, restore the backup immediately.
For serious sites, use version control. Even a private Git repository can save hours. You get a record of what changed, who changed it, and when it changed.
Final Recommendation
Treat wp-config.php as the control panel for WordPress internals. Treat .htaccess as the rulebook for Apache request handling. The two files can work together, but they do not do the same job.
When in doubt, ask one simple question: Is this setting about WordPress behavior, or is it about how the server handles a URL? If it is about credentials, debugging, salts, memory, or site constants, use wp-config.php. If it is about redirects, rewrites, access rules, or HTTP behavior, use .htaccess.



