Welcome guest, is this your first visit? Create Account now to join.
  • Login:

Members in Chat:
+ Reply to Thread
Results 1 to 1 of 1
  1. #1
    Will.Spencer's Avatar
    Will.Spencer is online now Skipper Recent Blog: Daily News Montenegro
    Join Date
    Dec 2008
    Location
    Singapore
    Posts
    6,352
    $NetBucks
    21,112
    Blog Entries
    1
    Thanked 2,295 Times in 1,244 Posts

    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>
    Submit Your Webmaster Related Sites to the NB Directory
    I swear, by my life and my love of it, that I will never live for the sake of another man, nor ask another man to live for mine.


 

Similar Threads

  1. Translation Script Error 503
    By ytutun in forum Translation Script Support
    Replies: 4
    Last Post: 3 October, 2010, 23:07 PM
  2. Translation Script Alternatives
    By Will.Spencer in forum Translation Script Support
    Replies: 17
    Last Post: 11 September, 2009, 19:53 PM
  3. Troubles with the Translation Script
    By quikned in forum Translation Script Support
    Replies: 4
    Last Post: 5 May, 2009, 03:06 AM
  4. Translation Script Version 2.15
    By Will.Spencer in forum Translation Script Support
    Replies: 9
    Last Post: 15 April, 2009, 10:15 AM
  5. Need help with this Translation Script!
    By coder77 in forum Translation Script Support
    Replies: 1
    Last Post: 26 February, 2009, 21:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts