• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

How do I prevent hotlinking in Plesk?

C

CBiLL

Guest
I tried several different rewrites in htaccess and they all are giving me a Internal server error when enabled ..

How do I prevent hotlinking using htaccess in Plesk?

Thanks
Bill
 
Welp .. I got hotlink block to work but it only stops the cgi scripts on the server from working ... ie forums or redirect etc etc and if I disable the hotlink block in htaccess it cgi script start working again ..

So what is Plesk doing that I need to get around to it to allow cgi script and hotlink block on my server?

Bill
 
Update .. I already added Addhandler and tried +ExecCGI in the htaccess and then put the hotlink rewrite back in but it still breaks the cgi scripts on my servers ..

Look like Plesk doesn't allow you to have rewrite and cgi scripts together ..

Also I took out the cgi redirect script and tried using htaccess redirect and then put the rewrite in it and it also broke htaccess redirect as well too ..

Something wrong with rewrite mod in Plesk it look like ..

Bill
 
Got it working without breaking the cgi scripts on the server ..

Had to add the rewrites in the domain's httpd.conf ..putting it in htaccess works but just breaks the any cgi scripts you have installed on your server..

Oh well I guess that's Plesk

Bill
 
Great conversation,

If you liked to post the solution then anybody with the same problem can be pointed in the right direction, or can use your solution!

Regards,

Pascal!
 
You use the same code for rewrite that you normally use in .htaccess but since putting it in htaccess in Plesk breaks any cgi script or redirects you have running on the server or in htaccess so then you will need to edit the domain's own httpd conf which is normally located in

/home/httpd/vhosts/yourdomain.com)/conf/httpd.include

and add this between the <VirtualHost your_server_ip:80> and </VirtualHost>

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpe?g|png|bmp)$ [F,NC]

You change "yourdomain.com" to the actual domainname you are trying to add hotlink preventation on.

And also you can add more of those per line

RewriteCond %{HTTP_REFERER} !^http://(www\.)?otherdomain.com(/)?.*$ [NC]



For each domain outside of your domain to allow them to hotlink your images so if you have people using your banner on thier site you need to add them to the RewriteCond. Change otherdomain.com to the actual domain you want to allow hotlinking to your server images ..

Restart httpd and you should be set ..

Bill
 
If you put anything in httpd.include it will be overwriten by Plesk. you should look at using the vhost.conf or vhost_ssl.conf which will not be overwriten by Plesk.
 
I already tried vhost.conf and it won't work at all ..

unless I am missing something ..

So far Plesk have not overwritten my httpd.include as of yet but when it does which I am sure it does at every upgrade .. Ill just put it back in there ..

Could you share how you would edit them in vhost.conf to enable hotlinking protection?

Bill
 
I'm not sure if it is possible but you could try putting your Rewrite directives between <directory /path/to/the/directory> and </directory>

As if you change any settings in the domain it will rewrite the httpd.conf file for the domain.
 
Remember when you create a vhost.conf for a (sub-)domain, you always need to run:

[path_to_your_psa]/admin/bin/websrvmng --vhost-name=<the host you've just changed>

To make Plesk register your vhost.conf file in the httpd.include setup.

And then restart Apache.
 
Hi,
wrote all the RewriteEngine stuff I had (and that was working on a other server without plesk) in the htaccess file in the vhost.conf

Executed websrvmng and tried to restart apache.

Apache stopps but does not restart, telling me the command "RewriteEngine" is not known.

If I try by putting directly "RewriteCond..." it is telling me, "unknown command RewriteCond.."

Anybody has a hint?
 
Originally posted by wenowo
Hi,
wrote all the RewriteEngine stuff I had (and that was working on a other server without plesk) in the htaccess file in the vhost.conf

Anybody has a hint?

You could start by including the configuration failing... include the section you've written in vhost.conf....
 
OK, here what I have now in vhost.conf

"
DirectoryIndex index.htm index.html index.php

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mywebsitesurl(/)?.*$
[NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp)$ http://mymainsite.com [R,NC]
"

But I don't think the problem lies here, because this worked well on my other server without plesk, by including that in my htaccess file.
 
Back
Top