views:

218

answers:

1

I recently moved a files/images folder on my site (a Drupal installation) from /sites/default/files/ to /sites/example.com/files/, but there are now a lot of 301 errors from external hotlinking sources, and I'd like to redirect inbound links from the old 'default' path to the new 'example . com' path, but only for this one domain...

Basically, I'd like to redirect visitors from the following:

example dot com /sites/default/files/*

to:

example dot com /sites/example.com/files/*

While allowing visitors from other domains (e.g. example2 dot com) to still see sites/default/files.

(Sorry for all the weird dot com and spacing, I'm only allowed to post a maximum of one 'hyperlink' - perhaps Stack Overflow should consider allowing example dot com as many times as needed).

+1  A: 

Try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} =example.com
RewriteRule ^sites/default/files/(.*) /sites/example.com/files/$1 [L,R=301]
Gumbo
Just a quick question about syntax - does the 'RewriteCond' get paired with the 'RewriteRule'? Meaning, if I added another Cond/Rule for another domain, would I just add that definition below the last line, and all would be well?
geerlingguy
Spiffy! Just redid the rule a little bit (as I had another rule to change non-www to www.example.com):<code>RewriteCond %{HTTP_HOST} www.lolsaints.com$ [NC]RewriteRule ^sites/default/files/(.*) /sites/lolsaints.com/files/$1 [L,R=301]</code>
geerlingguy