Website multilingual based on URL Folder and PHP Gettext - php

So I set up PHP to use Gettext and translate my website /index.php based on the language.
Now I would like to have the URL different for each language ( exemple : mydomain.com/fr/ ). But each folder should point to the main directory and PHP will change the language depending from wiched URL the user is using ( mydomain.com/fr/ or mydomain.com/it/ ).
What is the best way to do it ?

It is only up to your imagination (and your regex skills :-B but even I got it and my regex skills are rather weak.)
You could do www.mysite.com/articoli/Sed_ut_perspiciatis_unde_omnis/4711/ for the italian article
and
www.mysite.com/articles/far_far_way_behind_the_word_mountains/4711/ for the english version of the same article (product)
and you rewrite the first to
www.mysite.com/article.php?lang=it?article_id=4711
and the second to
www.mysite.com/article.php?lang=en?article_id=4711
(The middle part is discarded - look at ebay ads other pages with categories - they do it like this )
Takes you two regexp rewrites.
Basically you have to think about a structure logical to SEO and intuitive for users wgo sees the url.
This depends also on: what are the most visited pages of your site?
I have eg. only 1 php script/page which is responsible for 90% of all web traffic.
It used to be 2 (one per german and 1 in english but now I have it "gettext'ed" and now its only one page so much less maintenance.
If SEO optimization is interesting for you - look at similar well known pages and their page /URL structure.
Only rewriting mysite.com/fr/bubalu.html to mysite.com/bubalu.php?lang=fr will be useful only if you have very few pages and I ask myself if this really explains your site structure best to crawlers..

Related

Best way to manage multilingual website SEO friendly

I have a question regarding the creation of a multilingual website. In short I would like to send online a website and present it translated in 4 languages.
The most important thing is that the website is SEO friendly.
I have read several articles about this topic and some of them were published here.
In the end I decided to create sub-folders like this:
www.example.com/es for Spanish
www.example.com/de for German
and so on …
The main language will be English www.example.com.
Because it is the very first time I am dealing with this issue and I'd like to ask how to proceed.
At first sight, a similar approach makes me realize that each sub-folder www.example.com/es etc. will contain all the codes of the main site. This means that every time when I change something I have to copy/paste the change in each and every folder? Is there a more effective and dynamic way how to do that?
Rewrite URLs
E.g: mysite.com/en FOR mysite.com?lang=en
E.g 2: mysite.com/fr FOR mysite.com?lang=fr
Create a language array with combinaison of key => value in an inclusion file (e.g: inc.lang.php) such as
'en_apple' => Apple
'fr_apple' => Pomme
Replace terms to translate by your included array.
That's my way, it works for SEO (tested with Google tools) and it's light, because you have one directory to maintain for all your languages and it's invisible for users.
This is dynamic has you want, and you don't have to maintain 3 or 4 different folders each time you work on your website.
Hope it helps.
At first sight, a similar approach makes me realize that each
sub-folder www.example.com/es etc. will contain all the codes of the
main site. This means that every time when I change something I have
to copy/paste the change in each and every folder? Is there a more
effective and dynamic way how to do that?
No, you don't need to copy all the code of the main site. You only need to create the HTML content for each language and store it correspondingly in each directory. Then you need to learn about hreflang. It is not very hard, it is only about adding a couple of links in your header.

Writing a mutiple language website: the webdesigner's (best) options

They are some questions already about this on stackoverflow, but none is really clear about the 'best practice'.
For the content design, what are the options and what is the better option?
Some options I know are using folders: site.com/en/ and site.com/fr/ or redirects site.com/index.php?language=en
An even easier practice is using a new url: en.site.com and fr.site.com
But what if I want to keep site.com/index.php and nothing more ? What are my options for that?
For example, if you change the language on LinkedIn, there's nothing changing in the URL. How do they work there ?
update: in my case the website is a platform, using LAMP stack. Technical advice is also welcome (like how to store/link all the different language files)
You have some options, and each has its own advantages.
If you have a web app, which should not be indexed by search engines, then you are free to do whatever you want. You can keep a language setting in your Session and show strings in the chosen language. This will simplify URLs and management.
However, if you have a standard website which should go into Google, then your options are restricted. If you use the former approach, google will be confused and will index only one language, or, worse, make an ugly mix of the languages. Google does not keep sessions when indexing your page, so if you have two versions of the same page in two different languages, they need to have different URLs. And passing a language as a GET parameter each time is ugly, error prone, and not user friendly.
So you should either have languages as folders (eg. site.com/en/), which is the best options, or use subdomains. This can be a problem, however, because each subdomain is indexed as if it were a separate website, so things like pagerank and site reputation are split among the two.
Here are my recommendations based on multi-languages web sites experience
You can determine the language of the browser in Javascript (see this), which is a good start in having a language that likely fits the user demand
Use utf8 for encoding, everywhere (browser headers, programming, database). The only drawback I know of utf8 is that in some cases, the number of bytes it takes is bigger than another encoding matching more closely a given language (utf8 is opened to any). Big advantage, it covers any language, the ASCII part (bytes < 128) is the same as a western encoding (takes only one byte) ...
Store the user preferences (not in URL).
either in a cookie (+ : user does not have to be logged it on his computer to keep her prefs ; - : when user accesses the page from another computer, the cookie is not present and he/she has to reselect the pref).
or in a session (requires user login to deterime which user is currently using the site)
Regarding the site structure, if you don't store the user preferences, the common /us /fr /jp... solution has advantages: search engines robots will find all languages from root (the page display doesn't depend on user choice). Or you could load only a language dependent Javascript that displays the page immediately (after JS download) in the language of choice, without the need of a page reload / redirect.
You can tell Google what the parameters in the URL mean through Google's Webmaster Tools. So if you use a standard convention like index.php for the main page and a parameter like ?lang=fr for let's say French content in regard to SEO as long as it's a real translation. Likewise when Google.fr crawls the site you would present their users with the French version of the page based on their default setting in their browser. This will increase stickiness on the site and then increase the rank for the selected search terms in French. You can check their default language with this in PHP to make it less heavy on the user's end:
<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
echo $lang;
?>
Then you would simply concatenate the language selected (as an overlay) to the end of the query string (if it's not the default), bypassing the need for storing a cookie. This should also help from a user experience standpoint. It's not as "pretty" but if people aren't typing it in, it's much more user friendly in that:
People can switch languages by changing the variable
People can provide a link to a user in another country and they can be presented with the page in their native language intuitively when PHP checks their language. "Do you want to see this content in French?"
The native language could in theory be translated on the fly with something like the Google Translate Widget or Google Chrome's built-in functionality.
Content is only served on one URI per page meaning you would not have to rewrite several redirects between versions in the event of stale content. As you're not likely translating into both languages at the same time.
From Wikipedia on Chrome:
As of February 2013, according to StatCounter, Google Chrome has a 37%
worldwide usage share of web browsers making it the most widely used
web browser in the world.
As for storing the files, you can make separate tables in the database for each language, enter in the content in the native language, then duplicate that content to the other language's table. Then you could translate that content live on screen if so desired, or allow someone access to your CMS who could translate the content. Both records would have the same ID in the database so the page would be served appropriately when the language was looked up.
Large corporate sites do the handling of the URLs in a couple of ways, they would show french content at http://www.some_website.fr/ and English content at http://www.some_website.com/. Sites like wikipedia use a subdns so http://fr.wikipedia.org/ and http://en.wikipedia.org.
HTML5 supports the lang='fr' approach to declaring content on screen.
I don't know what's your situation but, imho, you shouldn't use new urls.. it would only be a useless waste of resources (all kinds of resources).. If your website's client-side is javascript-based, you could use libraries like i18next, which gives you great support in localizations.. That's a valid alternative if you agree leaving the localization at you application's client-side.
For server-side localization in php, i wouldn't be of any help..

How do I get translated URIs and controllers in CakePHP for a multi-lingual website

Hello all and thanks in advance for taking a look and I appreciate any help possible. I'm an SEO guy and have inherited a CakePHP site that will serve content in three languages. I'd like to get a canonical (seo friendly) way to get a good multilingual URL architecture without making my developer too upset.
The end solution of what we want:
Nice URLs with three distinct URLs (translated) for each language. For example:
www.domain.com/L1/language-1-parent/language-1-child/
www.domain.com/L2/language-2-parent/language-2-child/
www.domain.com/L3/language-3-parent/language-3-child/
Here, we have one content piece. This content will be the same in all three languages, but it will be translated. Accordingly, we want the corresponding subdirectories and URIs to be translated as well, where:
L{1-3} are subdirectories indicating the language
language-{1-3} are 'controllers' for the content. Currently we only have one controller, regardless whether the language subdirectories are in a different language).
langauge-{1-3}-child are dependent content items or subdirectries that must also be translated based upon the language subdirectories
The Assumed Problem:
My developer is telling me that because Cake has controllers that serve the content up and as such having translations is a bit messy.
In the example above: I assume that 'language-1,' language-2,' and 'language-3' are the controllers.
Also, I'm assuming that because we're trying to serve up three content versions from one controller (with different URLs), we're running into a problem.
Currently we have URLs as such:
www.domain.com/L1/language-1-parent/language-1-child/
www.domain.com/L2/language-1-parent/language-1-child/
www.domain.com/L3/language-1-parent/language-1-child/
The problem here is that regardless whether a user selects a different language, we have the URLs that do not correspond and are not translated.
Also, we do have some content items that do not have other language translations. As such, I want to put in a rel=canonical meta tag on the pages without translations and/or noindex these pages whilst we{re working on translations.
Again, your help is MASSIVELY appreciated and I look forward to your responses. I'm happy to clarify anything.
With standard cakephp configuration you can easily achieve these kind of URLs using cakephp internationlization
/eng/users/account
/fre/users/account
If you need these king of URLs
/eng/users/account
/fre/utilisateurs/compte
Then you should play with your AppController.php
// pseudo code, you need to rewrite this section as you need.
var lang getUrlParams['language'];
var controller getUrlParams['controller'];
var action getUrlParams['action'];
if (controller[lang] != controller || action[lang] != action) :
redirect to `/lang/controller[lang]/action[lang]`;
endif;
In view's all links should be called like
$this->Html->link(__('My Link'), array('controller' => __('users'), 'controller' => __('account')))

The best PHP search engine-friendly method

What method can you recommended for creating search engine-friendly URLs? When coding in PHP that is. Ideally I would like something like:
http://www.example.com/article/523544
So it doesn't display the file it's opening (eg article.php)
It is quite necessary to generate a SEO friendly URL's so that most of the Search engines can easily index it.And the most interesting part with it that URL can easily correlate to the Page Content and the User can generate a Pretty URL as per the keywords he want to rank the page on different Search Engines(e.g. google.com,google.co.in,bing.com)
The best example to have Pretty Links is on Wordpress.It actually stores the Dynamic Page URL's in the Database itself.And when the Pretty Ur is being called,internally the htaccess is called and it redirects to the original dynamic page in the system.
Some basic tips from
Google
SEOmoz
may help you.
Some topics in SO:
mod_rewrite
nice url
Edit:
You need to place a .htaccess file in your document root that includes the following rules:
RewriteEngine on
RewriteRule ^article/([0-9]+)?$ article.php?id=$1 [L]
Make sure mod_rewrite enabled in Apache and you are allowed to use it.
If you read some questions in SO in this topic it will help you understand how mod_rewrite works.
To make your urls more search engine friendly you may want to use 'slugs' so you need to sanitize your article titles like in this url.
Ideally your URL needs to contain something about the topic of the URL. You gave the example of http://www.example.com/article/523544, where this is better than using standard query strings, it's still not ideal, as all that any search engine can see from it is that it's an article.
It's important to remember that the segment (a segment is the string between each slash) closest to the domain is the most important:
http://www.example.com/most-important/next-important/less-important/
I personally always try to use the following URL structure, and keep my page/article titles unique:
http://www.example.com/this-wonderful-article
Notice the use of dashes and not underscores, this is generally known as the preferred method. Using this method I usually generate and save the article's slug ('this-wonderful-article') in the database, and then search for that instead of an ID.
Appreciated that sometimes it's very difficult to just use slug, especially with a larger website. You may have multiple articles with the same title, or the website may have user-submitted content over which you have no control. If this is the case, you can use the ID without any worries, but just be sure to include the title of the article in the URL. Eg: http://www.example.com/this-wonderful-article/29587
If you're looking for a method of using these URLs then I'd suggest looking at some mod_rewrite tutorials. Personally I use a framework that does the majority of the legwork for me such as CodeIgniter (http://www.codeigniter.com), or you could use something like the Zend Framework or CakePHP. If you're only doing articles then it might be worth looking into a sturdy CMS like WordPress, although this depends largely on your requirements.

REALLY basic mod_rewrite question

I am trying to use SEO-friendly URLs for a website. The website displays information in hierarchical manner. For instance, if my website was about cars I would want the URL 'http://example.com/ford' to show all Ford models stored in my 'cars' table. Then the URL 'http://example.com/ford/explorer' would show all the Ford Explorer Models (V-6, V-8, Premium, etc).
Now for the question:
Is mod_rewrite used to rewrite a query string style URL into a semantic URL, or the other way around? In other words, when I use JavaScript to set window.location=$URL, should the URL be the query string version 'http://example.com/page.php?type=ford&model=explorer' OR do I internally use 'http://example.com/ford/explorer' which then gives me access to the query string variables?
Hopefully, someone can see my confusion with this issue. For what it's worth, I do have unique 'slugs' made for all my top level categories (obviously, the site isn't about cars).
Thanks for all the help so far. I got the rewrite working but it is affecting other paths on the site (CSS, JavaScript, images). I using the correct path structure for all these includes (ie '/images/car.png' and '/css/main.css'). Do I have to use an absolute path ('http://example.com/css/main.css') for all files? Thanks!
Generally, people who use mod_rewrite use the terminology like this:
I want mod_rewrite to rewrite A to be B.
What this means is that any request from the outside world for page A gets rewritten to file B on the server.
You want the outside world to see URLs that look like
A) http://example.com/ford/explorer
but your web server wants them to look like
B) http://example.com/page.php?type=ford&model=explorer
I would say you want to rewrite (A) to look like (B), or you want to rewrite the semantic URL into a query string URL.
Since all the links on your page are clicked on by the user and/or requested by the browser, you want them to look like (A). This includes links that javascript uses in window.location. They can and should look like (A).
once you have set up mod_rewrite then your links should point to the mod_rewritten version of the URL (in your example: http://mysite.com/ford/explorer). Internally in your system you will still reference the variables as if they are traditional query string name value pairs though.
Its also worth pointing out that Google is now starting to advocate more logical URLs from a search engine point of view, i.e. a query string over mod rewrite
Does that mean I should avoid
rewriting dynamic URLs at all? That's
our recommendation, unless your
rewrites are limited to removing
unnecessary parameters, or you are
very diligent in removing all
parameters that could cause problems.
If you transform your dynamic URL to
make it look static you should be
aware that we might not be able to
interpret the information correctly in
all cases
http://googlewebmastercentral.blogspot.com/2008/09/dynamic-urls-vs-static-urls.html
also worth looking at:
http://googlewebmastercentral.blogspot.com/2009/08/optimize-your-crawling-indexing.html

Categories