To prevent image hotlinking using `.htaccess`, you can add the following code to your `.htaccess` file in the root directory of your website:
```apache
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain2.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
```
In the above code, make sure to replace `yourdomain.com` and `yourdomain2.com` with your actual domain names. This code uses mod_rewrite to perform the following steps:
1. Activate the rewrite engine.
2. Check if the `Referer` header is not empty.
3. Check if the `Referer` header does not match your domain(s) using regular expressions. You can add more `RewriteCond` lines for additional domains.
4. Check if the requested file has a `.jpg`, `.jpeg`, `.png`, or `.gif` extension (you can add more extensions if needed).
5. If all conditions are met, return a 403 Forbidden response (`[F]`) to block access to the image.
6. The `[NC]` flag makes the match case-insensitive.
7. The `[L]` flag stops the rewriting process.
This code will prevent direct access to images from external websites, but it allows them to be displayed on your own website.