Reputation: 5127
I have an apache config something like below:
RewriteCond %{QUERY_STRING} ^site=(eu|jp|in)$ [NC]
RewriteRule ^/?fetchHomePage.action$ https://example.com/%1? [R=301,L,NC]
RewriteCond %{QUERY_STRING} (?:^|&)site=(eu|jp|in)(?:&|$) [NC]
RewriteRule ^/?fetchFirstPage.action$ https://example.com/firstPage/%1? [R=301,L,NC]
RewriteCond %{QUERY_STRING} (?:^|&)site=(eu|jp|in) [NC]
RewriteRule ^/?fetchSecondPage.action$ https://example.com/secondPage/%1? [R=301,L,NC]
Can I store "(eu|jp|in)" in some variable and reuse that variable in all the three rewrite rules?
Leads here are appreciated?
Upvotes: 2
Views: 298
Reputation: 785128
(eu|jp|in)
is actually a regex expression. You can't really store that part in a variable but you can use a env variable to avoid repetition of same conditions as this:
# set env var QS if quesry string has site=(eu|jp|in)
RewriteCond %{QUERY_STRING} (?:^|&)site=(eu|jp|in)(?:&|$) [NC]
RewriteRule ^ - [E=QS:%1]
# now use value stored in QS variable
RewriteCond %{ENV:QS} ^(.+)$
RewriteRule ^/?fetchHomePage\.action$ https://example.com/%1? [R=301,L,NC]
RewriteCond %{ENV:QS} ^(.+)$
RewriteRule ^/?fetchFirstPage\.action$ https://example.com/firstPage/%1? [R=301,L,NC]
RewriteCond %{ENV:QS} ^(.+)$
RewriteRule ^/?fetchSecondPage\.action$ https://example.com/secondPage/%1? [R=301,L,NC]
Upvotes: 2