I have a file that contains RewriteRules for 200 countries (2 examples for 1 country below):
RewriteRule ^/at(/|/index.html|)$ http://%{HTTP_HOST}/locate/index.html?locale=de_AT [R=301,L]
#&
RewriteRule ^/at_english(/|/index.html|)$ http://%{HTTP_HOST}/locate/index.html?locale=en_AT [R=301,L]
I have another list of redirects for the mobile versions of these sites in the following format:
RewriteRule ^/at_engilsh(/|/index.html|)$ http://%{HTTP_HOST}m.website.com/www.website.com/at_engilsh [R=301,L]
Bear in mind the at_english is just 1 of the country codes, there are many more.
So my goals is to go from
RewriteRule ^/at_english(/|/index.html|)$ http://%{HTTP_HOST}/locate/index.html?locale=en_AT [R=301,L]
#to
RewriteRule ^/at_engilsh(/|/index.html|)$ http://%{HTTP_HOST}m.website.com/www.website.com/at_engilsh [R=301,L]
I'm supplying the awk / pseudo code for one way I've thought to do it.
awk '
{
newurl="m.website.com/www.website.com/"
one=substr($0,1,14)
two=substr($1,13,37)
rest=substr($4,1)
# The line below this comment is the section I'm having difficulty with because
#I have country codes in multiple formats at / at_engilsh / at_french
#I want to select all characters between ^/ ---> (
code=substr($2,1)
printf ("%s%s%s%s%s %s\n", one,code,two,newurl,code, rest)
}' input
So I either need help converting the pseudo code into actual code, or suggestions on a better way to do this operation.
Thank you for any help