Jump to content

Change language without ?language=English in URL


criat

Recommended Posts

Hello,

 

I use flags instead of language names in my WHMCS, and the code looks like this:

 

<a href="{$smarty.server.PHP_SELF}?language=english"><img src="en-flag.png"/></a>
<a href="{$smarty.server.PHP_SELF}?language=portuguese"><img src="pt-flag.png"/></a>

 

It works. When I click the portuguese flag it changes the language to portuguese, but the URL becomes

"http:/mysite.com?language=portuguese"

 

I'm looking for a way to change the language without changing the URL... Can anybody tell me how?

 

Thanks!!

Link to comment
Share on other sites

Keeping the same URL while showing the page into different languages is a very bad idea for SEO. There's a reason why Wikipedia uses it.wikipedia.org/wiki/Ferrari, en.wikipedia.org/wiki/Ferrari, Amazon amazon.it, amazon.fr and Apple apple.com/it, apple.com/fr and so on.

 

Let's take as example the home page of your WHMCS system. The URL is example.com/index.php. It doesn't matter in what language your are browsing it. It could be in English or Italian. The URL will always be the same (with the exception of the ?language=italian part that you see only as soon as you switch language).

 

Now the problem is that when search engines like Google will try to index your page with their spiders (aka crawlers or bots), they will notice that there's one page (index.php) that displays content in different languages. How can they index this page? Should they index it in Italian? English? Spanish? The result of this is that your page will only be indexed with the default language (e.g. English) and then it's almost impossible for you to attract Italians and Spanish customers. So why should you spend so much time with translations if only the default language will be indexed? It's a no-sense.

 

In case you have implemented geolocalization on your website (e.g. visitors from Italy automatically see example.com/index.php in Italian, Spanish in Spanish etc.) then there will be a total mess for spiders. You could be penalized.

 

Said that, you should have an unique URL for each version of page. In this way example.com/it/index.php will be index properly by spiders on google.it for Italians, example.com/fr/index.php on google.fr for french and so on.

Edited by Kian
Link to comment
Share on other sites

Yeah I totally agree with you, but I use this:

 

<html lang="{$LANG.isocode}">

 

Output:

 

Brasil:

<html lang="pt-br">

 

United States:

<html lang="en">

 

Simple yet very effective. It solves the problem, right?

Edited by criat
Link to comment
Share on other sites

Not really because language system in WHMCS is still based on $_SESSION. It can be easily extended to $_COOKIE but it is still not good for SEO. Spiders in fact only index what they can crawl visiting your page without the support sessions and cookies. So if you have a part of a page or an entire one that is "visible" thanks to a session or a cookie, the spider simply won't be able to crawl it. Every language should have a canonical (unique) URL.

Link to comment
Share on other sites

You can try something like such;

http://www.whmcs.com/members/communityaddons.php?action=viewmod&id=38

 

 

<a href="{$smarty.server.PHP_SELF}?language=English"><img  src="templates/{$template}/images/gb.jpg" title="English" alt="English"  width="31" height="21" border="0" /></a>
<a href="{$smarty.server.PHP_SELF}?language=English"><img  src="templates/{$template}/images/gb.jpg" title="English" alt="English"  width="31" height="21" border="0" /></a>
<a href="{$smarty.server.PHP_SELF}?language=Greek"><img  src="templates/{$template}/images/gr.jpg"  title="Ελληνικ?"   alt="Ελληνικ?"  width="31" height="21" border="0" /></a>
<a href="{$smarty.server.PHP_SELF}?language=Italian"><img  src="templates/{$template}/images/it.jpg" title="Italiano"  alt="Italiano" width="31" height="21" border="0" /></a>
<a href="{$smarty.server.PHP_SELF}?language=German"><img  src="templates/{$template}/images/de.jpg" title="Deutsch" alt="Deutsch"  width="31" height="21" border="0" /></a>
<a href="{$smarty.server.PHP_SELF}?language=French"><img  src="templates/{$template}/images/fr.jpg" title="Français"  alt="Français" width="31" height="21" border="0"  /></a>

Link to comment
Share on other sites

I've read about it on Google now.

 

Well, I think I'll have to make a HTML version of my site.

 

I would like to discuss it's structure here, before I do it.

 

First of all, I use HTTPS for everything in my site, it is good, right? My site strucutre would be like this then:

 

For HTML website, displaying products:

https://mysite.com -> English version

https://mysite.com/br -> Brazilian version

 

WHMCS would be on root as well, and would inherit the language specified by the HTML website:

https://mysite.com/clientarea.php

https://mysite.com/login.php

 

User would be automatically redirected to the right country based on their IP, and on the header there will be this, to allow changing countries if wrongly redirected:

Sem título.png

 

If the country could not be specified, it would go to default (english)

 

Example:

 

I'm actually brazilian.

 

1 - I type mysite.com

2 - Get redirected to https://mysite.com/br

3 - Then I can browse products or login to WHMCS.

4 - If I login, I expect some interaction between the HTML and WHMCS, such as:

 

4.1 - If Logged in:

sem titulo 2.png

4.2 - If Logged out:

(Show login fields instead)

 

5 - I click on a link to buy a product

5.1 - I get redirected to WHMCS checkout, where I can complete the order.

5.2 - I add a product to cart but don't checkout yet. It should display 1 item in cart, like this script

 

Is it all possible? Is it the best way to do it?

Do you guys have any sugestions?

 

Thanks a lot for letting me know about this.

Link to comment
Share on other sites

The best way to do this is to use URL_rewriting. See our site for a working example.

 

Add the following to your .htaccess for each language (the /whmcs folder is where whmcs is actually installed)

 


#force lang english
RewriteRule ^en/(.*).php?(.*)#(.*) /whmcs/$1.php?$2&language=english#$3 [NC,L,QSA] 
RewriteRule ^en/(.*).php?(.*) /whmcs/$1.php?$2&language=english [NC,L,QSA] 
RewriteRule ^en/(.*).php#(.*) /whmcs/$1.php?language=english#$2 [NC,L,QSA] 
RewriteRule ^en/(.*).php$ /whmcs/$1.php?language=english [NC,L,QSA] 
RewriteRule ^en/$ /whmcs/index.php?language=english  [NC,L,QSA] 
RewriteRule ^en/(.*) /whmcs/$1 [NC,L,QSA] 

#force lang italian
RewriteRule ^it/(.*).php?(.*)#(.*) /whmcs/$1.php?$2&language=italian#$3 [NC,L,QSA] 
RewriteRule ^it/(.*).php?(.*) /whmcs/$1.php?$2&language=italian [NC,L,QSA] 
RewriteRule ^it/(.*).php#(.*) /whmcs/$1.php?language=italian#$2 [NC,L,QSA]
RewriteRule ^it/(.*).php$ /whmcs/$1.php?language=italian [NC,L,QSA]
RewriteRule ^it/$ /whmcs/index.php?language=italian  [NC,L,QSA] 
RewriteRule ^it/(.*) /whmcs/$1 [NC,L,QSA] 

Link to comment
Share on other sites

 

User would be automatically redirected to the right country based on their IP, and on the header there will be this, to allow changing countries if wrongly redirected:

 

Please please do not use IP as a way to detect language, 1. it is not very reliable and 2. is actually quite offencive for people who don't speak the native language of the place they live. (e.g. I am English but happen to live in Italy but don't speak good Italian and I hate it if I am redirected to the italian site even though my browser language setting is english.)

 

Much better and much simpler is to just use the browser language setting.

 

Here is the PHP script we use to redirect customers to our specific language pages.

 


<?php 
if(isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])){
$langarray=explode(",", $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
$lang = strtolower($langarray[0]);
//echo $lang . " / " . $_COOKIE["Lang"] . " / ";
$stop=0; //change this to 1 to disable redirect
if ($_GET["stop"]!=1&&$stop!=1){
	if (isset($_COOKIE["Lang"])){
		if ($_COOKIE["Lang"]=="italian"){
			header("Location: " . $_SERVER["HOST"] . "it/"); 
		} else {
			header("Location: " . $_SERVER["HOST"] . "en/"); 	
		}
	} else {
		switch ($lang){
		case "en-au":
		case "en-bz":
		case "en-ca":
		case "en-029":
		case "en-gb":
		case "en-in":
		case "en-ie":
		case "en-jm":
		case "en-my":
		case "en-nz":
		case "en-ph":
		case "en-sg":
		case "en-za":
		case "en-tt":
		case "en-us":
		case "en-zw":
		case "en":
		case "gd":
		case "ga":
		case "ga-ie":
		case "cy-gb":
		case "cy":
			header("Location: " . $_SERVER["HOST"] . "en/"); 
			break;
		case "it":
		case "it-ch":
		case "it-it":
			header("Location: " . $_SERVER["HOST"] . "it/"); 
			break;
		case "es":
		case "es-es":
		case "es-ar":
		case "es-ve":
		case "es-bo":
		case "es-cl":
		case "es-co":
		case "es-cr":
		case "es-do":
		case "es-ec":
		case "es-sv":
		case "es-gt":
		case "es-hn":
		case "es-mx":
		case "es-ni":
		case "es-pa":
		case "es-py":
		case "es-pe":
		case "es-pr":
		case "es-us":
		case "es-uy":
			header("Location: " . $_SERVER["HOST"] . "es/"); 
			break;
		}
	}
}
}
?>

 

As you can see it checks to see if a "Lang" cookie is set and uses that as the clients language if it is, thus allowing the visitor to override the script on future visits if your site sets this cookie from a language choice in the site. Otherwise it looks at the browser language choice to picks the preferred language and defaults to english if it can't find a match.

Link to comment
Share on other sites

@ServWise

 

Thanks for the tips, I'll definitely use the browser lang redirect then

 

But, about the URL_Rewriting, I've just made my website in HTML from scratch, so now I'm thinking of sticking to it for displaying products and such.

 

The down points of using HTML in frontend is integrating codes like "Hello, client.name", because I have to see if client is online, grab his name and display there, and I still didn't find out how to do it.

 

- From the SEO point of view, from what I've read it seems to be fairly better

 

But one thing is annoying me: The affiliate system.

 

It won't work because of the redirects. Let's say my affiliate link is https://mysite.com?aff=004. When I access it, I go to https://mysite.com/br because of redirect, and the affiliate cookie simply won't grab. I'll make a topic of it

Link to comment
Share on other sites

  • 10 years later...
On 11/17/2013 at 12:58 PM, ServWise.com said:
#force lang english
RewriteRule ^en/(.*).php?(.*)#(.*) /whmcs/$1.php?$2&language=english#$3 [NC,L,QSA] 
RewriteRule ^en/(.*).php?(.*) /whmcs/$1.php?$2&language=english [NC,L,QSA] 
RewriteRule ^en/(.*).php#(.*) /whmcs/$1.php?language=english#$2 [NC,L,QSA] 
RewriteRule ^en/(.*).php$ /whmcs/$1.php?language=english [NC,L,QSA] 
RewriteRule ^en/$ /whmcs/index.php?language=english  [NC,L,QSA] 
RewriteRule ^en/(.*) /whmcs/$1 [NC,L,QSA] 

#force lang italian
RewriteRule ^it/(.*).php?(.*)#(.*) /whmcs/$1.php?$2&language=italian#$3 [NC,L,QSA] 
RewriteRule ^it/(.*).php?(.*) /whmcs/$1.php?$2&language=italian [NC,L,QSA] 
RewriteRule ^it/(.*).php#(.*) /whmcs/$1.php?language=italian#$2 [NC,L,QSA]
RewriteRule ^it/(.*).php$ /whmcs/$1.php?language=italian [NC,L,QSA]
RewriteRule ^it/$ /whmcs/index.php?language=italian  [NC,L,QSA] 
RewriteRule ^it/(.*) /whmcs/$1 [NC,L,QSA] 

 

Seems like this doesn't completely works on WHMCS v.8

All seems fine, except for the home page and any pages using index.php (announcements, password reset, etc).

Has anyone found a fix for this? Is it something with the new WHMCS rewriting these in the backend or a server config issue?

 

 

Link to comment
Share on other sites

Seriously I posted this 11 years ago and all WHMCS has done in that time is force customers into a per user monthly subscription (Even though this has no relation to their costs since it is a self-hosted system, same with cpanel) they are literally destroying the business sector they serve for their own profit, no win/win for these guys. AND still they don't have proper built-in multi-language capability, in fact they have made it even harder for people like me to bodge by moving a bunch of stuff to Laravel which won't support the same rewriting. Kinda sad when you think about it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated