Skip to content

Instantly share code, notes, and snippets.

@kisabelle
Last active October 18, 2017 23:57
Show Gist options
  • Save kisabelle/042d0a6cc377ecb0aba3634227d9d38e to your computer and use it in GitHub Desktop.
Save kisabelle/042d0a6cc377ecb0aba3634227d9d38e to your computer and use it in GitHub Desktop.
# Restrict direct access to PHP files from theme or plugin directories
# Place in root .htaccess file
# Restrict direct access to PHP files from plugin directories
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/directory/to/exclude/
RewriteRule wp-content/plugins/(.*\.php)$ - [R=404,L]
# Restrict direct access to PHP files from theme directories
RewriteCond %{REQUEST_URI} !^/wp-content/themes/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/themes/directory/to/exclude/
RewriteRule wp-content/themes/(.*\.php)$ - [R=404,L]
// Prevent Direct Access to Theme/Plugin files
// Place at the top of your theme or plugin files
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment