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'];
CommentFileSizeAuthor
#7 languages_inc_1.patch680 bytesainigma32
#5 languages_inc_0.patch680 bytesainigma32
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

Why can't you setup multiple virtual servers within the apache configuration?

markus_petrux’s picture

Well, 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?

c960657’s picture

Alternatively, 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.

markus_petrux’s picture

Sure, "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".

ainigma32’s picture

Version: 6.x-dev » 7.x-dev
Status: Postponed (maintainer needs more info) » Needs review
FileSize
680 bytes

I don't know what the consequences of changing this would be but I've attached a patch to get the discussion started again.

- Arie

Status: Needs review » Needs work

The last submitted patch failed testing.

ainigma32’s picture

Status: Needs work » Needs review
FileSize
680 bytes

Hmmm no idea why that failed.

Rerolled.

- Arie

Damien Tournoud’s picture

Status: Needs review » Reviewed & tested by the community

Makes total sense. We have no test coverage for this (that's not easy, and we will have to think about it).

salvis’s picture

#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.)

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD and DRUPAL-6. Thanks.

markus_petrux’s picture

Committed to CVS HEAD and DRUPAL-6.

Thank you! :-D

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.