I have been told that for Google to be able to search your pages properly, the URL must be distinct.
Currently, I am using same URL for a page but using session variables in PHP to change the language and the contents. Every phrases that is different for each language is output for a session variable.
Like, http://kowbow.com/index.php will have different content when user choose a different language.
So some Google consultant said must use mod_rewrite to change the URL into http://kowbow.com/en/ for English and http://kowbow.com/de/ for German.
Problem is that I am using Window 2003 shared hosting. That means it's not Apache. And the Google consultant said to use mod_rewrite which is for Apache.
Also another problem is that some of my URLs are dynamic. For instance, http://kowbow.com/getstuff.php?stuffid=xxxxx with xxxx being a running number from my mysql table.
I know that I can maintain actual folders for each language but that would mean lots of duplicate files to update. Btw, I am currently supporting 7 languages, 2 more to come. Probably more in the future. I am hoping to maintain one set of files but appear to the user that for different languages, the URL is distinct like
http://kowbow.com/en/getstuff.php?stuffid=xxxx for English and http://kowbow.com/de/getstuff.php?stuffid=xxxx for German.
Anyone know how to do the distinct URL thing? I really don't want to maintain one folder for each language. BTW, I am the only one doing this website.
P.S. kowbow.com is just an example. That is not my real site. Also very important is that any solution must work on IIS (Windows 2003) as well as Apache (Debian Linux). This is because my testing website is Window 2003 but my actual customer's website is Debian Linux.
Why not just install an Apache server on your computer and test the site locally?
I have not worked on an IIS server so far, so I can't help you much with that. But as for mod_rewrite, you can always pass the language variable to your PHP script with a RewriteRule in the .htaccess file like:
RewriteRule ([a-z]{2})/(.*) /index.php?lang=$1&path=$2
This will internally redirect (as in it won't be visible to the user - the URL remains intact) requests like http://example.com/en/Haruhi to http://example.com/index.php?lang=en&path=Haruhi.
You may need to switch on the RewriteEngine with the line below prior to any RewriteRule statement if it is not by default.
RewriteEngine On
To support multiple langauges, you would still have to either maintain a file or use a database table to store the text for each language being used. The translated text can be inserted into the page via defined constants which is similar to what is done in osCommerce. Like:
require_once $lang . '_constants.php';
<h2><?=TOPIC_TITLE?></h2>
<p><?=TOPIC_TEXT?></p>
Then in en_constants.php, you may have:
define('TOPIC_TITLE', 'Hello World!');
define('TOPIC_TEXT', 'Bla Bla Bla');
And in cn_constants.php, it may be :
define('TOPIC_TITLE', '哈喽, 世界!');
define('TOPIC_TEXT', '�啦 �啦 �啦');
Or you can choose to store them all in a database table and pull them out in a similar fashion. Either way, please remember to sanitize all input data (eg. the language variable).
If you want to pass the stuffid in a "cleaner" way, like how sgForums pass the forum ID and topic ID in the URL, you can always turn to, once again, mod_rewrite. You can either modify the above RewriteRule and the script to suit this purpose, or, if you have already coded the getstuff.php page and everything is pretty much rigid, you can try adding the below rule on top of the above one.
RewriteRule ([a-z]{2})/getstuff/([0-9]+)/? /getstuff.php?lang=$1&stuffid=$2 [L]
So, if the user looks for a page like http://example.com/en/getstuff/1234, the request will be internally redirected to http://example.com/getstuff.php?lang=en&stuffid=1234.
Thanks for your reply. I just found out that my hosting has ISAPI_Rewrite which simulates mod_rewrite on IIS. So I should be able to use the .htaccess after all.
I cannot test locally because my customer is viewing the test website too. He is doing his own testing on my test website and giving me feedback.
I am not too sure of the syntax for RewriteRule yet. Never done it before. I guess I have to go and read the Apache website documentations.
Btw, I am already storing my translations in a mysql table. Then when a language is chosen, I store them into session variables.
This part is the one that most interests me:
So, if the user looks for a page like http://example.com/en/getstuff/1234, the request will be internally redirected to http://example.com/getstuff.php?lang=en&stuffid=1234
Only thing is that I call a page to load the translations. I don't load the translations in every page. Maybe I can tweak it a bit to get it to work with lang=en in the URL.
Originally posted by GIB:Thanks for your reply. I just found out that my hosting has ISAPI_Rewrite which simulates mod_rewrite on IIS. So I should be able to use the .htaccess after all.
I cannot test locally because my customer is viewing the test website too. He is doing his own testing on my test website and giving me feedback.
I am not too sure of the syntax for RewriteRule yet. Never done it before. I guess I have to go and read the Apache website documentations.
Btw, I am already storing my translations in a mysql table. Then when a language is chosen, I store them into session variables.
This part is the one that most interests me:
Only thing is that I call a page to load the translations. I don't load the translations in every page. Maybe I can tweak it a bit to get it to work with lang=en in the URL.
Well, for your client to test the site on your computer, all you have to do is to keep your computer on, make sure port 80 is accessible and let him know your IP address, or subscribe to a Dynamic DNS service to create a hostname that points to your computer whenever you're online. That's what I did for my last few clients.
And yea, just Google "mod_rewrite" for more information. The official documentation is really detailed and the examples they provide gives you a good idea of its syntax and workings.
Anyway, you may want to consider storing the language variable client-side as a browser cookie as well, so that it can be stored permanently, or at least until the visitor clears his/her cookies.
Originally posted by LatecomerX:Well, for your client to test the site on your computer, all you have to do is to keep your computer on, make sure port 80 is accessible and let him know your IP address, or subscribe to a Dynamic DNS service to create a hostname that points to your computer whenever you're online. That's what I did for my last few clients.
And yea, just Google "mod_rewrite" for more information. The official documentation is really detailed and the examples they provide gives you a good idea of its syntax and workings.
Anyway, you may want to consider storing the language variable client-side as a browser cookie as well, so that it can be stored permanently, or at least until the visitor clears his/her cookies.
Well, my company already has its own website and I just created a new subdomain for testing. Also I don't keep my PC on when I go home. With a real website, the customer can go play with it any time he wants. Which he does.
As for the cookies, the customer specifically don't want cookies.
Originally posted by GIB:Well, my company already has its own website and I just created a new subdomain for testing. Also I don't keep my PC on when I go home. With a real website, the customer can go play with it any time he wants. Which he does.
As for the cookies, the customer specifically don't want cookies.
Oh ok. I thought you were working from home. Anyway, by calling session_start() and using $_SESSION, the script creates a cookie which is named "PHPSESSID" by default in the visitor's browser. So unless you are passing the PHPSESSID value through the URL, you are actually using a cookie already. And I find it weird that your client requests for zero cookie being used in the script. Does he/she has a grudge against them or something?
If I remember correctly, his users had some problem with cookies in their browsers. So he requests that whatever I do, I should avoid cookies.
Yeah, I know session variables are cookies. But he doesn't know that.
Besides, the users that were having problems with cookies did not have problems with session variables. Or something like that.