Hi,
I'm running running PHP 5.2.6, Apache 2 and working on a multiligual site.
For this site, Apache has a single virtual host defined with a ServerName like www.example.com and a wildcard ServerAlias like *.example.com
In this environment, $_SERVER['SERVER_NAME'] always is www.example.com, so I cannot setup the Drupal site to select current language based on domain.
On the other hand, $_SERVER['HTTP_HOST'] contains the domain as passed on the URL, which is what I would need.
Would it be better to use $_SERVER['HTTP_HOST'] rather than $_SERVER['SERVER_NAME']? If so, the change in core would be something like this:
In includes/language.inc, around line 28:
if (!empty($parts['host']) && ($_SERVER['SERVER_NAME'] == $parts['host'])) {
Replace with:
if (!empty($parts['host']) && ($_SERVER['HTTP_HOST'] == $parts['host'])) {
In the meantime, I've included the following line at the bottom of settings.php:
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
Comment | File | Size | Author |
---|---|---|---|
#7 | languages_inc_1.patch | 680 bytes | ainigma32 |
#5 | languages_inc_0.patch | 680 bytes | ainigma32 |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedWhy can't you setup multiple virtual servers within the apache configuration?
Comment #2
markus_petrux CreditAttribution: markus_petrux commentedWell, say I'm planning to support 3 languages, each with a different subdomain in the form [langcode].example.com.
1) I can use a single Virtual host with wildcards on the ServerAlias *.example.com, ServerName is www.example.com.
2) I can use as many Virtual hosts, each with its own ServerName.
Ok, but what if I plan to support 4, 5, 6, or even more languages. How long would be my httpd.conf? Also, everytime I need to add a new language, I would have to modify httpd.conf and restart Apaches, etc.
If I already have a layer where I can control if a sudomain is valid, then... is there anything wrong using HTTP_POST?
hmmm... say this is not a bug report, but a feature request, please let me choose if I prefer SERVER_NAME or HTTP_POST for my particular environment?
Comment #3
c960657 CreditAttribution: c960657 commentedAlternatively, adding "UseCanonicalName Off" to your Apache config will also fix the problem (I think).
However, I agree that language.inc should use HTTP_HOST rather than SERVER_NAME.
Comment #4
markus_petrux CreditAttribution: markus_petrux commentedSure, "UseCanonicalName Off" would be an alternative, though you may still need to know which is the ServerName, say you run another application behind the same virtual host that needs "UseCanonicalName On".
Comment #5
ainigma32 CreditAttribution: ainigma32 commentedI don't know what the consequences of changing this would be but I've attached a patch to get the discussion started again.
- Arie
Comment #7
ainigma32 CreditAttribution: ainigma32 commentedHmmm no idea why that failed.
Rerolled.
- Arie
Comment #8
Damien Tournoud CreditAttribution: Damien Tournoud commentedMakes total sense. We have no test coverage for this (that's not easy, and we will have to think about it).
Comment #9
salvis#2: I'm only just making my first steps with running a multi-language site, but there's a third possibility:
3) Instead of a wildcard ServerAlias *.example.com, you can also have multiple ServerAliases, one for each language subdomain.
There's no need for multiple virtual hosts, and your issue seems to be the result of using the wildcard.
(My virtual host is example.com and www.example.com is a ServerAlias, like en.example.com and de.example.com, and this works fine.)
Comment #10
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD and DRUPAL-6. Thanks.
Comment #11
markus_petrux CreditAttribution: markus_petrux commentedThank you! :-D