Would you like to learn how to install Apache and prevent image hotlinking? In this tutorial, we are going to configure the Apache server to block image hotlinking on your website.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Apache 2.4.41

In our example, the Apache server is hosting the website WWW.GAMEKING.TIPS.

Copyright © 2018-2021 by Techexpert.tips.
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means without the prior written permission of the publisher.

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Apache - Prevent image hotlinking

Install the Apache server.

Copy to Clipboard

Edit the Apache configuration file for the default website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Change this line to your domain name.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will forbid hotlinking to images on our website.

In our example, the Apache server will allow direct access to images on our website.

From a remote Linux computer, try to perform hotlinking to an image.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

The Apache server will forbid hotlinking to images on our website.

From a remote Linux computer, try to perform direct access to an image.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

The Apache server will allow direct access to images on our website.

Congratulation! You configured the Apache server to block image hotlinking.

Tutorial Apache - Blocking image hotlinking

Install the Apache server.

Copy to Clipboard

Enable the required Apache modules.

Copy to Clipboard

Edit the Apache configuration file for the default website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Change this line to your domain name.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will forbid hotlinking to images on our website.

In our example, the Apache server will allow direct access to images on our website.

From a remote Linux computer, try to perform hotlinking to an image.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

The Apache server will forbid hotlinking to images on our website.

From a remote Linux computer, try to perform direct access to an image.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

The Apache server will allow direct access to images on our website.

Congratulation! You configured the Apache server to block image hotlinking.

Tutorial Apache - Redirect image hotlinking

Install the Apache server.

Copy to Clipboard

Enable the required Apache modules.

Copy to Clipboard

Edit the Apache configuration file for the default website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Change this line to your domain name.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will redirect image hotlinking on our website.

In our example, the Apache server will allow direct access to images on our website.

From a remote Linux computer, try to perform hotlinking to an image.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

The Apache server will redirect image hotlinking on our website.

From a remote Linux computer, try to perform direct access to an image.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

The Apache server will allow direct access to images on our website.

Congratulation! You configured the Apache server to redirect image hotlinking.

Tutorial Apache - Rewrite image hotlinking

Install the Apache server.

Copy to Clipboard

Enable the required Apache modules.

Copy to Clipboard

Edit the Apache configuration file for the default website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Change this line to your domain name.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will redirect image hotlinking on our website to another local image.

In our example, the Apache server will allow direct access to images on our website.

From a remote Linux computer, try to perform hotlinking to an image.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

The Apache server will redirect image hotlinking on our website to another local image.

From a remote Linux computer, try to perform direct access to an image.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

The Apache server will allow direct access to images on our website.

Congratulation! You configured the Apache server to redirect image hotlinking to a local image.