这可以通过使用脚本来实现(根据您的需要进行修改):
#!/bin/bash
# Dynamic IP .htaccess file generator
# Written by Star Dot Hosting
# www.stardothosting.com
dynDomain="$1"
htaccessLoc="$2"
dynIP=$(/usr/bin/dig +short $dynDomain)
echo "dynip: $dynIP"
# verify dynIP resembles an IP
if ! echo -n $dynIP | grep -Eq "[0-9.]+"; then
exit 1
fi
# if dynIP has changed
if ! cat $htaccessLoc | /bin/grep -q "$dynIP"; then
# grab the old IP
oldIP=`cat /usr/local/bin/htold-ip.txt`
# output .htaccess file
echo "order deny,allow" > $htaccessLoc 2>&1
echo "allow from $dynIP" >> $htaccessLoc 2>&1
echo "allow from x.x.x.x" >> $htaccessLoc 2>&1
echo "deny from all" >> $htaccessLoc 2>&1
# save the new ip to remove next time it changes, overwriting previous old IP
echo $dynIP > /usr/local/bin/htold-ip.txt
fi
不仅仅是 cron 它在 .htaccess 文件上生成一个新行:
*/15 * * * * /bin/sh /usr/local/bin/.sh yourhostname.no-ip.org /var/www/folder/.htaccess > /dev/null 2>&1
来源:https ://www.stardothosting.com