Make Domain-Specific folder redirect using .htaccess rules?
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).
Try this mod_rewrite rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} =example.com
RewriteRule ^sites/default/files/(.*) /sites/example.com/files/$1 [L,R=301]
精彩评论