Works fine, until i noticed Google had indexed de.mydomain.co.uk/englishcategoryname/… pages! Not sure how it found these as they are not linked on site, however, they do function as (english) pages but with the de subdomain and are obviously causing duplicate content with the www versions.
How can i force all language subdomains use their appropriate translated urls?
I don’t know how your mod_rewrite could have been working for you as you’ve ANDed your German and Spanish blocks then ANDed the UK block to those (which must be false - if there was a RewriteCond involved.
For me, I would have used:
# add www subdomain if not es|de|www
RewriteCond %{HTTP_HOST} !^es\\.
RewriteCond %{HTTP_HOST} !^de\\.
RewriteCond %{HTTP_HOST} !^www\\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Add lang query sting value to de|es subdomains if it's not already been assigned
RewriteCond %{HTTP_HOST} !^www\\.mydomain\\.co\\.uk
RewriteCond %{HTTP_HOST} ^(de|es)\\.mydomain\\.co\\.uk
RewriteCond %{QUERY_STRING} !lang=%1
RewriteRule .? %{REQUEST_URI}?lang=%1 [L]
# es|de assigned - just keep them with QSA flag
# ES
RewriteCond %{QUERY_STRING} lang=es
RewriteRule ^spanishcategoryname/(.*)$ mypage.php?i=$1 [QSA,L]
RewriteCond %{QUERY_STRING} lang=es
RewriteRule ^spanishmainpage\\.html$ mypage2.php [QSA,L]
# DE
RewriteCond %{QUERY_STRING} lang=de
RewriteRule ^germancategoryname/(.*)$ mypage.php?i=$1 [QSA,L]
RewriteCond %{QUERY_STRING} lang=de
RewriteRule ^germanmainpage\\.html mypage2.php [QSA,L]
#GB
RewriteCond %{QUERY_STRING} !lang=(es|de)
RewriteRule ^englishcategoryname/(.*)$ mypage.php?i=$1&lang=gb [QSA,L]
RewriteCond %{QUERY_STRING} lang=gb
RewriteRule ^(.+)\\.html$ $1.php [QSA,L]
The biggest problems you had here were:
Assigning the lang value to the query string
Maintaining that value throughout with the QSA flag
Forgetting the Last flag
Forgetting to escape the dot character in the regex and
Using the No Case flag in RewriteRules (which ARE case sensitive)
Personally, I would have assigned gb to lang in the same block that es|de were assigned - for consistency if no other reason.