While trying to install the module i got the following Error.

Fatal error: Call to undefined function: str_ireplace() in /SERVER_PATH/sites/all/modules/domain/domain.module on line 43

Comments

derjochenmeyer’s picture

Oh, im running drupal on PHP 4.4.7 and str_ireplace seems to be PHP 5 only.

"WWW Prefix Handling" does that:

  // Strip the www. off the subdomain, if required.
  if (variable_get('domain_www', 0)) {
    $_subdomain = str_ireplace('www.', '', $_subdomain);
  }

Is PHP 5 required by other parts of the module? Would this be an option:

  // Strip the www. off the subdomain, if required.
  if (variable_get('domain_www', 0)) {
    $_subdomain = str_replace('www.', '', strtolower($_subdomain));
  }

Question: I'm doing a similar thing with mod_rewrite. What are the benefits from using the "WWW Prefix Handling" option?

<IfModule mod_rewrite.c>
  RewriteEngine on
	
  # redirects domain and any subdomain to www-less version
  RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
  RewriteRule ^(.*) http://%1/$1 [L,R=301]

  RewriteBase /

  # Rewrite current-style URLs of the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
agentrickard’s picture

Status: Active » Reviewed & tested by the community

My mistake. Didn't read up on str_ireplace() well enough.

The benefit to the WWW Prefix Handling is only for people on shared hosts who cannot control mod_rewrite. Your solution is actually better.

This is not worth a patch. But the fix is noted above.

agentrickard’s picture

This issue also requires us to case-check the incoming URL, since www.example.com == WWW.EXAMPLE.com per the url specification.

Lines 38-44 of domain module become:

  // Cribbed from bootstrap.inc -- removes port protocols from the host value.
  $_subdomain = strtolower(implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));

  // Strip the www. off the subdomain, if required.
  if (variable_get('domain_www', 0)) {
    $_subdomain = str_replace('www.', '', $_subdomain);
  }
agentrickard’s picture

Status: Reviewed & tested by the community » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

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