Htaccess fake subdomain issue

I have htaccess processing the subdomain (de|es etc) and applying it to relevant pages as …?lang=de etc…

RewriteCond %{HTTP_HOST} !^es\\.
RewriteCond %{HTTP_HOST} !^de\\.
RewriteCond %{HTTP_HOST} !^www\\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} !^www\\.mydomain\\.co\\.uk
RewriteCond %{HTTP_HOST} ^(de|es)\\.mydomain\\.co\\.uk
RewriteRule ^$ ?lang=%1 [L] 

# ES
RewriteRule ^spanishcategoryname/(.*)$ mypage.php?i=$1&lang=es [nc]
RewriteRule ^spanishmainpage.html mypage2.php?lang=es [nc]

# DE
RewriteRule ^germancategoryname/(.*)$ mypage.php?i=$1&lang=de [nc]
RewriteRule ^germanmainpage.html mypage2.php?lang=de [nc]

#GB
RewriteRule ^englishcategoryname/(.*)$ mypage.php?i=$1&lang=gb [QSA]
RewriteRule ^(.*)\\.html$ /$1.php [nc]


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?

sky,

As much as I rely on mod_rewrite, Apache’s Content Negotiation is your answer.

Regards,

DK

sky,

I’m involved with my computer just now - give me overnight to do the mod_rewrite version for you.

Regards,

DK

sky,

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:

  1. Assigning the lang value to the query string

  2. Maintaining that value throughout with the QSA flag

  3. Forgetting the Last flag

  4. Forgetting to escape the dot character in the regex and

  5. 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.

Regards,

DK

Ah thanks. Could you give mean example of what I might need using this?