I want a mod_rewrite rule to redirect url with respect to the hostname they're comming from.

The problem:

We've multiple domain names pointing to some same webspace and we have to restrict exactly what the specific host can easily seeOrobtain.

domainname.com/images/logo design.digital and /www.domainname.com/images/logo design.digital should transform into domainname.com/domainname_com/images/logo design.digital

So essentially I want a guideOrperform that replaces the dots within the % with _ and removes/replaces the www subdomain.

Can there be any method of doing this with mod_rewrite?

You can only use virtual hosts configuration.

Try these rules:

RewriteCond %{ENV:DOMAIN_DIR} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^images/.+ - [E=DOMAIN_DIR:%2]

RewriteCond %{ENV:DOMAIN_DIR} ^([^.]*)\.(.+)
RewriteRule ^images/.+ - [E=DOMAIN_DIR:%1_%2,N]

RewriteCond %{ENV:DOMAIN_DIR} ^[^.]+$
RewriteRule ^images/.+ %{ENV:DOMAIN_DIR}/$0 [L]

The very first rule will require the host and store it without www. within the atmosphere variable DOMAIN_DIR. The 2nd rule will replace one us dot at any given time the N flag enables to restart the spinning process without incrementing the interior recursion counter. Finally, the 3rd rule will rewrite the request towards the corresponding directory.