Hotlink Protection in Hostmonster's CPanel

So far I have been quite happy with hostmonster’s performance and quality. It is not really that good, but for the price, I get what I pay for. There is this one problem in the Hotlink Protection that I never bother to fix.  Sometimes ago, I enabled hotlink protection, and when I tried to disable it, suddenly all of my WordPress blogs permalinks stops working. I didn’t know what was wrong, and I just re-enabled the hotlink protection. Today I found out that the problem is in CPanel, it removes the "RewriteEngine  on" line from the .htaccess files when you turn off the hotlink protection (after turning it on).

Re-adding the "RewriteEngine on" to the first line of the .htaccess files fixed that. I have several blogs, so editing one by one will take a long time, so I did the editing from command line. Inserting a text to the first line of a file can be done using sed:

sed -i '1i\RewriteEngine on' $i filename

And to change a lot of files at once you can do this (bash shell):

for i in dir1/.htaccess dir2/.htaccess  ; do sed -i '1i\RewriteEngine on' $i; done

Leave a Reply

Your email address will not be published. Required fields are marked *