Security

Securing Your WordPress Directory Structure: How to Block Access to the "wp-includes" Folder

  • 15 min read
  • Hostragons Team
Securing Your WordPress Directory Structure: How to Block Access to the "wp-includes" Folder

Securing Your WordPress Directory Structure involves blocking direct access to the "wp-includes" folder by preventing external execution of PHP files and disabling directory listing, rather than completely blocking the folder itself. This is important because wp-includes contains essential JavaScript, CSS, and some static files necessary for the core functionality of WordPress. Blocking access to the entire folder might disrupt site design, editor functionality, or plugin operations. The proper approach is to block direct PHP access using .htaccess rules if you are using Apache, or through a location rule within the server block if you are using Nginx, and then validate the site with 403/404 responses and critical page tests.

One of the most common mistakes in WordPress security is relying solely on strong passwords or security plugins. Attackers often scan for directories containing core files, outdated plugins, incorrect file permissions, and open directory listings. The wp-includes folder is also one of the targets of these scans. In this guide, you will find actionable steps to limit access to wp-includes in real hosting environments, rules that could break your site, example configurations for Apache and Nginx, testing methods, and a maintenance checklist. You may also consider WordPress Hosting to run your WordPress site on a more secure infrastructure, and SSL Certificate for an additional layer of protection.

What is the wp-includes Folder and Why Should It Be Protected?

wp-includes is one of the main directories containing the core libraries of WordPress. It houses the theme system, block editor, REST API components, media handling, classes, functions, and various JavaScript files. Simply put, wp-includes is one of the engine rooms of WordPress and is not a content area that users should directly visit.

A normal visitor does not need to access site.com/wp-includes/. However, some static assets under wp-includes might be visible in the page's source code. For instance, default script files, emoji scripts, or editor components of WordPress can be loaded from this directory. Therefore, when implementing security measures, it is crucial to target correctly: blocking direct web access to PHP files without stopping the execution of static files.

This distinction is fundamental to a professional approach to WordPress directory structure security. Randomly closing folders might seem secure in the short term, but it can lead to issues such as a blank page on the live site, a broken admin panel, a non-functional block editor, or a faulty theme appearance. The goal is to narrow the attack surface by protecting the files required by WordPress.

What Does Blocking Access to wp-includes Achieve?

Blocking direct PHP execution in the wp-includes folder alone does not stop all attacks; however, it significantly reduces the attack surface. Particularly on malware-infected sites, attackers attempt to upload malicious PHP files to accessible directories or call existing files. Prohibiting the direct execution of PHP files under wp-includes creates an additional barrier in such scenarios.

This measure provides the following benefits:

  • Limits direct URL calls to core PHP files.
  • Helps prevent folder content from being visible if directory listing is enabled.
  • Reduces unnecessary information leakage against automated bot scans.
  • Provides server-level protection even without a security plugin.
  • Strengthens layered security when combined with WAF, SSL, up-to-date PHP, and proper file permissions.

The important point here is that this action is a layer of security. If you have outdated plugins, weak admin passwords, or compromised FTP accounts, the wp-includes rule alone is not sufficient. Security is a combination of hosting infrastructure, application, user management, and regular maintenance. For a secure foundation, refer to Secure Web Hosting and for additional protection in domain management, check Domain Security.

Common Mistakes When Blocking wp-includes

Blocking the Entire Folder

The most common mistake is to block all HTTP requests to the wp-includes folder with a 403 response. This method seems logical at first glance; however, since WordPress loads some static assets from this directory, it can cause unexpected issues. For example, the block editor might not load, certain JavaScript files may fail to load, or minor yet critical design issues could appear on the frontend.

Deploying the Rule Live Without Testing

A single character error in the .htaccess or Nginx configuration can produce a 500 Internal Server Error. It is particularly risky to apply the rule directly to high-traffic sites. Before applying changes, backup the file, test in a staging environment if possible, and then proceed cautiously to the live site. If staging or backup options are available in the Hostragons infrastructure, Web Hosting Backup can be added as a natural internal link.

Relying Entirely on Security Plugins

Security plugins are helpful; however, server-level rules come into play at an earlier stage. If a request is blocked by Apache or Nginx before reaching PHP, resource consumption is reduced. Therefore, even if a plugin is used, basic server rules should not be overlooked.

Pre-Implementation Checklist

Doing a short preparation before limiting access to wp-includes significantly reduces the risk of downtime. The following checklist is especially recommended for live WordPress sites:

  • Back up your existing .htaccess or Nginx configuration.
  • Update the WordPress core, themes, and plugins.
  • Ensure that your PHP version is a supported and secure version.
  • Check file permissions: folders should generally be 755, and files 644.
  • Do not leave write permissions unnecessarily open for critical files like wp-config.php and .htaccess.
  • If using a cache, CDN, or security plugin, plan to clear the cache after making changes.
  • Create a list of critical areas to test, such as the admin panel, homepage, post page, contact form, and checkout page.

This preparation takes about 10-15 minutes; however, it prevents downtime that could last for hours due to a wrong rule. It is safer to make changes on corporate sites during low-traffic hours.

Blocking PHP Access to wp-includes Using .htaccess on Apache Server

The most common method on shared hosting using Apache is the .htaccess file. Adding the right rules to the .htaccess file located in the WordPress root directory can block specific PHP calls in wp-includes. Before starting the process, download a copy of the file to your computer or create a backup through the file manager in the hosting panel.

The following approach focuses on blocking direct PHP access under wp-includes while preserving the execution of static files:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^wp-includes/.*[.]php$ - [F,L]
</IfModule>

The logic of this rule is simple: if the URL starts with wp-includes and ends with .php, the request is forbidden. This way, PHP files in wp-includes cannot be called from the browser. In contrast, access to static files such as .js, .css, .png, and .svg continues. This is a safer balance for the frontend and admin panel of WordPress.

Disabling Directory Listing

Another critical setting is to disable directory listing. If directory listing is enabled on the server, users can see the contents of certain folders. Adding the following line to your main .htaccess file is usually sufficient:

Options -Indexes

This line prevents the file list from being displayed in folders without an index file. In modern hosting environments, this is often disabled by default; however, it's good security practice to check.

Testing After Changes

After adding the rule, conduct the following tests:

  • Open siteaddress.com/wp-includes/; the directory listing should not be visible.
  • Try to directly call a known PHP file under wp-includes; you should receive a 403 or 404 response.
  • Check the homepage, blog post, and admin panel.
  • Look for 404/403 resource errors in the Console and Network tabs of the browser developer tools.
  • If using a cache plugin or CDN, clear the cache.

If all tests are successful, the rule can be safely left in the production environment. If you receive a 500 error, the quickest solution is to remove the lines you added and restore the backup .htaccess file.

Blocking PHP Access to wp-includes on Nginx Server

On VPS, dedicated, or managed server environments using Nginx, .htaccess will not work. You need to add the rule to the Nginx site configuration file, usually within the server block. This requires SSH access and permission to edit the configuration files. If you are unsure, it is safer to seek help from your hosting support team.

The basic rule can be implemented as follows:

location ~* ^/wp-includes/.*[.]php$ {
deny all;
}

This rule blocks requests to PHP files under wp-includes. It is important to test the configuration after making changes:

nginx -t

If the test is successful, Nginx is reloaded:

systemctl reload nginx

Here, the reload command is more controlled than the restart command; it refreshes the configuration without completely dropping active connections. However, it is still advisable to make changes to critical sites during low traffic periods.

Considerations When Using Nginx

  • Ensure that you are adding the rule to the correct server block; there may be multiple sites on the same server.
  • If using a CDN or reverse proxy, conduct real tests after clearing the CDN cache.
  • Verify that the PHP-FPM configuration only processes the necessary files.
  • Check the log files: access.log and error.log will quickly show any faulty rules.

In a Nginx environment, an incorrect location order may yield unexpected results. Therefore, ensure that the rule does not conflict with WordPress permalink and PHP processing blocks.

Comparison of Methods

The following table summarizes the main methods used to limit access to wp-includes:

Comparison of Methods
MethodSuitable EnvironmentAdvantagePoint of Caution
.htaccess RuleApache and LiteSpeed HostingQuick to implement, accessible on shared hostingIncorrect syntax can lead to a 500 error
Nginx Location RuleVPS, Dedicated, Managed ServerStrong and performant at the server levelSSH and configuration knowledge required
Security PluginUsers with limited technical knowledgeEasy management via interfaceNot every rule may be applied at the server level
WAF and CDNHigh-traffic or attacked sitesFilters bots, brute force, and malicious requests earlyIncorrect rules can block real users
File PermissionsAll WordPress SitesBasic security hygieneDoes not block URL access alone

In practice, the best results come from using these methods in combination. For example, when the .htaccess rule on Apache hosting, correct file permissions, an up-to-date WordPress core, SSL, and regular backups come together, layered defense is established. Since a firewall and isolation are also critical in hosting infrastructure, choosing Corporate Hosting can make a difference for critical sites.

File Permissions and Ownership Settings

Blocking access to wp-includes falls short if file permissions are incorrect. The generally accepted permissions in WordPress are 755 for folders and 644 for files. These values allow the web server to read the files while reducing unnecessary write permissions. Some specialized hosting environments may have different user and group configurations; therefore, you should also consider the recommendations of your panel.

In particular, 777 permission poses a serious security risk. Allowing everyone to write to a folder facilitates scenarios for malicious file uploads. Even in directories like wp-content/uploads, which should be writable, PHP execution should be blocked. Under normal circumstances, wp-includes should not be writable by users except during WordPress updates.

In a security audit, the following values can be checked:

  • wp-includes folder: generally 755
  • PHP files within wp-includes: generally 644
  • wp-config.php: preferably 600 or more restrictive permissions suitable for the hosting structure
  • .htaccess: generally 644, without unnecessary write permissions after editing

These settings may not behave the same on every server. Incorrect permissions can prevent the site from updating or reading files. After changes, a WordPress health check and error logs should be reviewed.

Do Security Plugins Handle This Process?

Security plugins like Wordfence, iThemes Security can automatically suggest some hardening rules. These plugins are valuable in areas such as brute force protection, file change monitoring, malware scanning, and login security. However, it is essential to check what the plugin does regarding blocking access to wp-includes.

Some plugins automatically add rules to the .htaccess file. Others only provide application-level protection. Application-level protection activates once the request reaches WordPress, which is not as early as server-level blocking. Therefore, the professional approach is to evaluate the plugin in conjunction with server configuration.

If you are using a security plugin, consider the following checks:

  • Check whether the plugin adds .htaccess or Nginx rules.
  • Ensure that two different rules doing the same job do not conflict.
  • Verify that security settings have not changed after a plugin update.
  • Monitor cache and server resource usage to measure the performance impact.

Using multiple security plugins at the same time is often not a good idea. Conflicting firewall, login, and rewrite rules can reduce performance or cause incorrect blocks.

Testing wp-includes Protection: A Practical Scenario

To determine if the application has been successful, merely opening the site is not sufficient. The following 7-step practical test can be applied to most WordPress installations, from small business sites to e-commerce projects:

  • 1. Open the homepage in an incognito tab and check for visual distortions.
  • 2. Visit a blog post, category page, and search result page.
  • 3. Log into the wp-admin panel; open the block editor and media library.
  • 4. Check the Console tab in the browser developer tools.
  • 5. Verify that static files under wp-includes are not unnecessarily blocked in the Network tab.
  • 6. Attempt a direct call to a PHP file under wp-includes; expect a 403 or 404 response.
  • 7. Inspect the server error logs for any new or recurring errors.

This test takes about 5 minutes and quickly captures misconfigurations. Especially on sites with payment processes like WooCommerce, cart, checkout, and user account pages should also be tested separately. Even a small JavaScript block can affect conversion rates on live revenue-generating sites.

Additional WordPress Directory Structure Security Measures

Protecting wp-includes is a good start; however, WordPress security should be considered holistically. The following additional measures further reduce the attack surface:

  • Keep the core updated instead of trying to hide the WordPress version.
  • Completely delete unused themes and plugins.
  • Make the admin username hard to guess.
  • Use two-factor authentication.
  • Restrict access to XML-RPC if not in use.
  • Apply rate limiting or additional verification for wp-login.php.
  • Automate backup and restore testing.
  • Use HTTPS site-wide; login credentials are at risk without SSL.

While SSL does not directly block access to wp-includes, it provides essential security for user sessions, form data, and admin panel traffic. Therefore, SSL is always one of the first layers in WordPress security guides. At this point, Buy SSL Certificate and Free SSL Installation can be integrated naturally within the content.

When Should You Seek Professional Support?

Adding an .htaccess rule on simple Apache hosting is manageable for most users. However, if you have a specialized Nginx configuration, a multi-site network, a WooCommerce store, a high-traffic news site, or a corporate portal, it may be better to seek professional support. Because security rules should not only be technically correct but also securely implemented for business continuity.

Expert assistance is recommended in the following situations:

  • If you are hosting multiple WordPress sites on the server.
  • If using Nginx, Varnish, CDN, and WAF together.
  • If you notice an increase in 403, 404, or 500 errors after recent changes.
  • If the site has experienced malware infections in the past.
  • If you are running a system that processes payments, memberships, or personal data.

A secure hosting infrastructure, proper isolation, regular backups, and expert support are the unseen but critical components of WordPress security. When selecting infrastructure, consider not just disk space, but also backup, firewall, PHP version support, SSL management, and the quality of technical support. In this context, Hostragons Hosting Packages and WordPress Site Migration may be helpful for the reader.

Conclusion

The correct way to block access to the wp-includes folder under WordPress directory structure security is not to block the entire folder but to restrict direct web access to PHP files within wp-includes and disable directory listings. This process can be quickly applied with .htaccess for Apache and location rules for Nginx. However, it is essential to back up before any change and to conduct tests on the admin panel and frontend afterward.

In short: do not disrupt static files, limit PHP access, disable directory listing, check file permissions, and perform regular updates. For a more secure and manageable WordPress infrastructure, you can explore Hostragons’ hosting, domain, and SSL solutions and get support for the configuration that suits your needs.

Frequently Asked Questions

Is it safe to completely block the wp-includes folder?

Generally, it is not recommended. wp-includes may contain JavaScript, CSS, and static files needed by WordPress. Complete blocking may disrupt the site’s appearance or admin panel. A more secure approach is to block direct access to PHP files in this folder.

What should I do if I get a 500 error after adding an .htaccess rule?

First, remove the last rules you added or restore the backup .htaccess file. Then check the rule for syntax errors. If the error persists, review the hosting error logs or seek help from technical support.

Does .htaccess work on Nginx server?

No. .htaccess is used in Apache and LiteSpeed environments. In Nginx servers, similar restrictions are implemented using location rules within the server block and should be tested with nginx -t after modification.

Does this process make my WordPress site completely secure?

No. Blocking access to wp-includes PHP is an important layer of security but is not sufficient alone. Updates, strong passwords, two-factor authentication, SSL, backups, firewalls, and correct file permissions must be applied together.

If I am using a security plugin, should I also add the wp-includes rule?

It depends on what rules the plugin is applying. Some plugins add .htaccess rules; others only provide application-level protection. Limiting server-level PHP access without creating conflicts is generally a stronger solution.

Share this article:

Hostragons Team

Up-to-date guides from our expert team on hosting, servers, and domain names. Let's find the right solution for your project together.

Contact Us