F
F
full-size2017-10-25 21:38:08
htaccess
full-size, 2017-10-25 21:38:08

How to protect yourself from hotlink on shared hosting?

Site on WordPress
Site on virtual hosting, editing the configuration file is not possible (as the hoster claims).
Purpose: protection against hotlink using the .htaccess file. on virtual hosting with nginx + apache bundle
The usual code does not work because (from technical support response):
"The nginx + apache bundle works on our servers. Static files with extensions are given through nginx: jpg, jpeg, gif, png, css
This means files are not processed through apache and if there are any directives in the .htaccess file, then they will not work either.
In order for Apache to process these files, you need to create links to files with a different extension, or to files that do not exist on the server. In this case, the request will be passed to the Apache web server, and you can use .htaccess directives to process these requests!
Explain in a human way how all this should be done using a specific example, using what code?
There is a solution on the Internet only for editing the server configuration file, of course I don’t have access to it!
Perhaps there are other solutions to this problem, who knows, tell me pliz.
A solution was found on the network to replace the root index.php, but it did not give any result:

<?php
ob_start();
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
$searches = array(
      '/wp-content/uploads/2013/04/',
      '/wp-content/uploads/2013/05/',
      '/wp-content/uploads/2013/06/'
      );
      
$replaces = array(
      '/images/04/', 
      '/images/05/',
      '/images/06/'	
      );
      
$buffer = str_ireplace($searches, $replaces, ob_get_contents());
ob_end_clean();
echo $buffer;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Vorotnev, 2017-10-26
@HeadOnFire

If Nginx is at the input, then it doesn’t matter what you do there for statics (pictures, styles, scripts) in .htaccess - the request to Apache (and, accordingly, to the processing of rules in .htaccess) will never reach. For this, Nginx is installed at the entrance.
Hotlink protection on Nginx is easy with just one rule for your virtual host . If the hoster does not give you the opportunity to edit the config of your virtual host (or at least part of it), you need to change the hoster. I don't see any other way to solve your problem. Is it a CDN, as Mikhail writes (in fact, this is another Nginx at the entrance before everything else, but this time you can edit the config, unlike your hosting).

M
Mike, 2017-10-26
@MikeKosulin

1. Move to another hosting.
Because if nginx + apache is used, then requests go through nginx for statics, and everything that is not static is proxied to Apache, therefore .htaccess will not help.
2. Use hotlink protection via CDN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question