NetBuilders

You are welcome to look around. You will have to register before you can post a message, create a blog, chat live with our members, or add a site to our directory.




Reply Steve Fortuna
Old 5 February, 2009, 05:48 AM   #1 (permalink)
Gozer
 
Will.Spencer's Avatar
 
Location: Singapore
iTrader: (45)
Blog Entries: 1
Thanked 1,622 Times in 890 Posts
Posts: 4,958
$NetBucks: 8,563
Join Date: Dec 2008
Last Online: Today 08:07 AM
Default Configuring the Translation Script to Use Subdomains

Several people have asked for a feature which will enable the translation script to use subdomains (es.example.com) instead of subdirectories (www.example.com/es/).

Implementing this is not simple. The difficulties are mostly related to configuring your web server and DNS for subdomains. In comparison, configuring the script is easy.

I just made these changes on another one of my domains and used that change process to create this documentation.

Configure Apache for Subdomains

The first step is to configure Apache for subdomains.

The instructions for this are site specific.

Here's what I did.

I replaced this section in /usr/local/etc/apache22/extras/httpd-vhosts:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot /usr/local/www/data/example.com
ServerName http://www.example.com
ServerAlias example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com(:80)?$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R=301]
ErrorLog logs/example.com-error_log
CustomLog logs/example.com-access_log combined
</VirtualHost>
Here's what I replaced it with:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot /usr/local/www/data/example.com
ServerName http://www.example.com
ServerAlias example.com *.example.com
RewriteEngine on
ErrorLog logs/example.com-error_log
CustomLog logs/example.com-access_log combined
</VirtualHost>
This removed the automatic redirect from example.com to www.example.com, but we'll add that back in a moment.

Configuring DNS for Subdomains

The next step is to configure your DNS for subdomains.

Once again, the steps to accomplish this are very site specific.

We're running BIND here, so I added these records to the zone file for this domain:
en IN A 123.123.123.123
de IN A 123.123.123.123
es IN A 123.123.123.123
fr IN A 123.123.123.123
it IN A 123.123.123.123
pt IN A 123.123.123.123
ru IN A 123.123.123.123
nl IN A 123.123.123.123
el IN A 123.123.123.123
hi IN A 123.123.123.123
ja IN A 123.123.123.123
ko IN A 123.123.123.123
zh-cn IN A 123.123.123.123
zh-tw IN A 123.123.123.123
ar IN A 123.123.123.123
Edit /.htaccess

Next we will add three sections of code to the domains main .htaccess file.

This first section sends visitors to the right language, based upon the subdomain they use. It is also where we now block directories and file extensions which we don't wish to translate.
# Hostname based language selection
RewriteCond %{HTTP_HOST} !^www.*
RewriteCond %{REQUEST_URI} !^/includes/.*
RewriteCond %{REQUEST_URI} !^/images/.*
RewriteCond %{REQUEST_URI} !\.(exe|gz|zip|rar|asp|js|jsp|php|pdf|xls|mp3|avi| mpg|mpeg|wmv|gif|png|jpg|bmp|css|ico|GIF|JPG|PNG|f eed|trackback)$
RewriteRule ^(.*)$ /translate/index.php?page=$1 [L]
This section adds 301 redirects from the old subdirectory URL's to the new subdomain URL's.
# Redirects for v2 translation URLs
Redirect 301 /lang/en/ http://www.example.com/
Redirect 301 /lang/de/ http://de.example.com/
Redirect 301 /lang/es/ http://es.example.com/
Redirect 301 /lang/fr/ http://fr.example.com/
Redirect 301 /lang/it/ http://it.example.com/
Redirect 301 /lang/pt/ http://pt.example.com/
Redirect 301 /lang/ru/ http://ru.example.com/
Redirect 301 /lang/nl/ http://nl.example.com/
Redirect 301 /lang/el/ http://el.example.com/
Redirect 301 /lang/ja/ http://ja.example.com/
Redirect 301 /lang/ko/ http://ko.example.com/
Redirect 301 /lang/zh-TW/ http://zh-TW.example.com/
Redirect 301 /lang/zh-CN/ http://zh-CN.example.com/
Redirect 301 /lang/ar/ http://ar.example.com/
The third section replaces the non-www to www.redirect that I removed from httpd-vhosts and also adds a redirect for en (English) to www.
# Redirect to www.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^en.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Edit the Calls to the Translation Script

I was calling the translation script like this:
Code:
<a href="/lang/es<?php echo $_SERVER["REQUEST_URI"] ?>">Spanish<img src="/images/es.png" width="16" height="11" alt="Spanish"></a>
I edited these calls to use subdomains, like this:
Code:
<a href="http://es.example.com<?php echo $_SERVER["REQUEST_URI"] ?>">Spanish<img src="/images/es.png" width="16" height="11" alt="Spanish"></a></td>
  Reply With Quote
Reply

Bookmarks

Tags
configuring, script, subdomains, translation


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
404 Error with the Translation Script davesnake Translation Script Support 59 14 September, 2009 07:58 AM
Need help with this Translation Script! coder77 Translation Script Support 1 26 February, 2009 20:05 PM


All times are GMT. The time now is 09:53 AM.
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.1
vBAdvertise v1.0.0 Copyright ©2009, PixelFX Studios
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios