Remove WordPress’ license.txt using plugin

I want to write a plugin to return HTTP 404 when user request license.txt, what is the correct action to hook (both efficient and effective way to block)?

Update:

Read More

Because I don’t have control to the web server, I must do this as a plugin

Related posts

Leave a Reply

3 comments

  1. Solution is actually pretty straightforward.
    You need to create plugin which writes to .htaccess.

    1. In the /wp-content/plugins create licence_redirect folder.
    2. In that folder create licence_redirect.php file.
    3. Paste code below to this licence_redirect.php php file:
    <?php
    /*
    Plugin Name: Licence redirect
    Description: Redirects license.txt. to 404
    Author: J. Wrong
    Version: 0.1
    */
    ?>
    <?php
    function lr_flush_rewrites() {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }
    
    function lr_add_rewrites() {
        global $wp_rewrite;
        $lr_wp_rules = array(
            'license.txt$' => '[R=404,L]',
        );
    
        $wp_rewrite->non_wp_rules = $lr_wp_rules + $wp_rewrite->non_wp_rules;
    }
    
    register_activation_hook( __FILE__, 'lr_flush_rewrites' );
    add_action('generate_rewrite_rules', 'lr_add_rewrites');
    
    1. Install and activate plugin.
    2. In admin panel go to Setting -> Permalinks
    3. Press save changes
      From now on your license.txt requests will be redirected to 404.
      If you can’t create folders on server then you’ll need to zip the plugin’s folder and upload it using WP admin.
      Cheers… counting bounty now 😛