• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

The RIGHT Way To Block PHP Files in Wp-Includes In WordPress

Bhagwad Park

Published on: May 11, 2020

Categories: WordPress 1

NameHero has a partnership with DropMySite to backup your website on a daily basis. One of the advantages of this, is that it allows you to see which files are modified – particularly, the error logs can be quite useful. Recently, this allowed me to isolate a recurring error logged in a “php_errorlog” file that looks like this:

Error Thrown in module.audio.ac3.php
Error Thrown in module.audio.ac3.php

As you can see, my site WP-Tweaks was throwing an error that said:

“Uncaught Error: Class ‘getid3_handler’ not found” in the file “module.audio.ac3.php”. Doing a Google search for the result, leads to this bug report page, which suggests a fix for WordPress users by securing the .htaccess file to disallow direct PHP execution in the wp-includes folder. Unfortunately, the page located here doesn’t fix the problem. Specifically, this line:

RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]

Only blocks PHP files directly inside the wp-includes folder. It doesn’t block files inside the sub folders. To do that, the line needs to be:

RewriteRule ^wp-includes\/.*\.php$ - [F,L]

Creating .htaccess Rules to Protect ALL PHP Files in Wp-Includes

To test this regex expression check out this amazing tool regex101.com – I’ve saved the modified regex so you can see how it blocks PHP files both directly inside wp-includes, as well as subfolders:

New Regex Blocks all PHP Files
New Regex Blocks all PHP Files

You can also see that it doesn’t block other files like CSS files that might need to be called directly. Only PHP files, as expected.

For reference, the previous regex as given on the WordPress support pages doesn’t block all PHP files. Here’s a screenshot of the old regex:

Old Regex Not Blocking the First Line
Old Regex Not Blocking the First Line

You can see that while this regex matches “somephpfile.php” directly inside wp-includes, it doesn’t match the file that actually caused the error – wp-includes/ID3/module.audio.ac3.

Final .htaccess Code

So here’s the modified code that you need to insert into the top lines of .htaccess OUTSIDE the #Begin WordPress tags:

# Block the include-only files.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes\/.*\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>

If you paste this code, it’ll keep your wp-includes folder secure. Anyone who tries to access a file inside it will get a “403” Forbidden message like this:

Direct PHP Access Blocked
Direct PHP Access Blocked

And that’s it!

Bottom Line

To draw the attention of the WordPress community to this problem, I posted a note on the forums. The moderator replied back saying that there was no problem if you wanted to block all PHP code like this. Even though he said that it wasn’t necessarily a security concern, he mentioned there might be future problems if someone were to hack your site and run the malicious PHP files.

So better safe than sorry right?

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

Blogger vs. WordPress: Which One to Use?

Let's compare WordPress and Blogger across five key areas. Then, we'll show you how to set up a professional blog with WordPress.

How To Start A Newsletter In WordPress

Check out our complete guide on why and how you should start your own newsletter in WordPress.

How to Eliminate Render-Blocking Resources in WordPress (& Why You Should)

Many things can slow down your site, including render-blocking resources. These are CSS and JavaScript files that delay the loading of content on your site. As a result, visitors will have to wait longer to interact with your page, which could lead to frustration and instant exits.  So, what can you do to eliminate render-blocking […]

What Is Self-Hosted WordPress?

In this post, we’ll differentiate self-hosted WordPress from WordPress.com, and discuss the benefits of the former.

Reader Interactions

Comments

  1. kristina ponting says

    September 30, 2022 at 6:48 am

    I works very well – made it on my blogs:)

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA