Reputation: 10131
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:
Because I don't have control to the web server, I must do this as a plugin
Upvotes: 2
Views: 2899
Reputation: 677
There is a plug-in that will do this for you. Just set the file you want to redirect and its target. It even keeps a log
http://wordpress.org/extend/plugins/redirection/
Upvotes: 1
Reputation: 1020
Solution is actually pretty straightforward. You need to create plugin which writes to .htaccess.
<?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');
Upvotes: 7
Reputation:
You can't. With a standard WordPress .htaccess
, requests to static files are not passed to PHP at all, so there is no way to hook them.
Upvotes: 2