Forum Moderators: phranque
Instead of backslash escaping spaces, you can surround the entire flags argument with double quotes:"[E=example:Lorem ipsum dolor sit amet consectetur]"
<H3 data-logo onClick="location.href='%{ENV:home}';">${lc:$1}</H3> RewriteRule ^ - [E=foo:<H3\ data-logo\ onClick="location.href=\ '%{ENV:home}';">${lc:$1}</H3>] RewriteRule ^ - '[E=foo:<H3 data-logo onClick="location.href='%{ENV:home}';">${lc:$1}</H3>]' # Using \ to escape the nested '
RewriteRule ^ - '[E=foo:<H3 data-logo onClick="location.href= \'%{ENV:home}\';">${lc:$1}</H3>]'
# Double-escaping
RewriteRule ^ - '[E=foo:<H3 data-logo onClick="location.href= \\'%{ENV:home}\\';">${lc:$1}</H3>]'
# Triple-escaping
RewriteRule ^ - '[E=foo:<H3 data-logo onClick="location.href= \\\'%{ENV:home}\\\';">${lc:$1}</H3>]'
# Using a double quote to wrap, then escaping the doubles instead
RewriteRule ^ - "[E=foo:<H3 data-logo onClick=\"location.href= '%{ENV:home}';\">${lc:$1}</H3>]"
# Using a tilde to wrap instead of '
RewriteRule ^ - `[E=foo:<H3 data-logo onClick="location.href= '%{ENV:home}';">${lc:$1}</H3>]`
RewriteRule ^ - [E=foo:"location.href='%{ENV:home}';"]
RewriteRule ^ - "[E=foo:<H3 data-logo onClick=%{ENV:foo}>${lc:$1}</H3>]"
I'm setting a variable that's a string like this:<H3 data-logo onClick="location.href='%{ENV:home}';">${lc:$1}</H3>
It looks like you are going beyond what "simple environment variables" are meant to be used for.
I assume you are expecting "%{ENV:home}" and "${lc:$1}" to be evaluated before the value is assigned to the env var (ie. you don't want to store this literal text in the env var?!), but what is "$1" supposed to refer to in this example? (In the examples you posted, the $1 backreference is always empty.)
# %{ENV:domain} is determined earlier
RewriteCond %{ENV:domain} ^example?$
# I also let the user define the domain with example.com?default=whatever
RewriteCond %{QUERY_STRING} !(?:^|&)default=[a-z]+ [NC]
# define all of the allowed first-level pages
# if it's not one of these then the first level must be one of the pre-defined possibilities
RewriteCond %{REQUEST_URI} !^/(?:lorem|ipsum|53_others)[/$] [NC]
# $1 is the first level of the URL
# %{ENV:home} is defined earlier, too
# I actually set 4 variables here, so this is abbreviated to the relevant part
RewriteRule ^/([a-z]+) - [E=foo:<H3\ data-logo\ onClick="location.href='%{ENV:home}';">${lc:$1}</H3>] However, you can also build up the final value using multiple directives to avoid complex escaping.
RewriteRule ^ - [E=bar:"location.href='%{ENV:home}';"]
RewriteCond %{ENV:domain} ^example?$
RewriteCond %{QUERY_STRING} !(?:^|&)default=[a-z]+ [NC]
RewriteCond %{REQUEST_URI} !^/(?:lorem|ipsum|53_others)[/$] [NC]
RewriteRule ^/([a-z]+) - "[E=foo:<H3 data-logo onClick=%{ENV:bar}>${lc:$1}</H3>]"