As already mentioned, the RewriteCond
(condition) directive itself applies only to the first RewriteRule
that follows. The RewriteCond
directive forms part of a single rule.
However, you can "workaround" this in various ways, without having to apply the same condition to multiple rules.
For example:
# Skip the following 4 rules when host is NOT "example.com"
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
RewriteRule ^ - [S=4]
# These rules only apply to "example.com"
RewriteRule ^1example$ / [R=302,L]
RewriteRule ^2example$ /example2 [R=302,L]
RewriteRule ^3example$ / [R=302,L]
RewriteRule ^4example$ /example4 [R=302,L]
# Skip the following 4 rules when host is NOT "example.net"
RewriteCond %{HTTP_HOST} !^(www\.)?example\.net [NC]
RewriteRule ^ - [S=4]
# These rules only apply to "example.net"
RewriteRule ^5example$ /sgsg [R=302,L]
RewriteRule ^6example$ /example2 [R=302,L]
RewriteRule ^7example$ / [R=302,L]
RewriteRule ^8example$ /example44 [R=302,L]
# Skip the following 4 rules when host is NOT "example.uk"
RewriteCond %{HTTP_HOST} !^(www\.)?example\.uk [NC]
RewriteRule ^ - [S=4]
# These rules only apply to "example.uk"
RewriteRule ^9example$ / [R=302,L]
RewriteRule ^10example$ /example12 [R=302,L]
RewriteRule ^11example$ / [R=302,L]
RewriteRule ^12example$ /example41 [R=302,L]
Alternatively, you could temporarily prefix the hostname to the URL-path and test for this directly in the RewriteRule
directive.
For example:
# Prefix the hostname to the URL-path
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com|example\.net|example\.uk)
RewriteRule ^ %1%{REQUEST_URI}
RewriteRule ^example\.com/1example$ / [R=302,L]
RewriteRule ^example\.com/2example$ /example2 [R=302,L]
RewriteRule ^example\.com/3example$ / [R=302,L]
RewriteRule ^example\.com/4example$ /example4 [R=302,L]
RewriteRule ^example\.net/5example$ /sgsg [R=302,L]
RewriteRule ^example\.net/6example$ /example2 [R=302,L]
RewriteRule ^example\.net/7example$ / [R=302,L]
RewriteRule ^example\.net/8example$ /example44 [R=302,L]
RewriteRule ^example\.uk/9example$ / [R=302,L]
RewriteRule ^example\.uk/10example$ /example12 [R=302,L]
RewriteRule ^example\.uk/11example$ / [R=302,L]
RewriteRule ^example\.uk/12example$ /example41 [R=302,L]
# (OPTIONAL) Remove hostname prefix from URL-path
RewriteRule ^[^/]+/(.*) $1