mod_rewrite

Apache rewrite rules for hosting multiple domains

Friday, February 24th, 2006

RewriteCond %{HTTP_HOST}  site1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/vhosts/site1/.*$
RewriteRule ^(.*)$  /vhosts/site1/$1 [L]
RewriteCond %{HTTP_HOST}  site2.com$ [NC]
RewriteCond %{REQUEST_URI} !^/vhosts/site2/.*$
RewriteRule ^(.*)$  /vhosts/site2/$1 [L]

TechRepublic has more.

Blocking certain sites from hotlinking images via mod_rewrite

Saturday, February 18th, 2006

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite1\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite2\.com/ [NC]
RewriteRule \.(jpe?g|gif|png)$ images/no_hotlink.jpg [L]

Displaying another image when someone hotlinks

Saturday, February 18th, 2006

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpe?g|gif|png)$ images/no_hotlink.jpg [L]

Preventing hotlinking images from any domain except Yahoo! Image Search and Google Images

Saturday, February 18th, 2006

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(images\.)?yahoo\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(images\.)?google\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpe?g|gif|png)$ - [F]

Keep on coding