FOLLOW USJoomlashack FacebookJoomlashack TwitterJoomlashack Google +Joomlashack RSS

Joomlashack logo blog
Published on 18 May 2007

Joomla Errors and the www. Domain Mismatch

Many Joomla users, particularly newbies (newcomers or beginners), fall victim to a variety of issues which have the same root cause. The so called www domain mismatch causes a wide variety of issues such as login failures (both core and Community Builder logins, and administrator logins), WYSIWYG editors failing to load or failing to save content, javascript execution halted with error messages. At JoomlaShack our own Flash based JPG Rotator is triggered by javascript and this module is amongst those affected.

What Causes This?

http://www.yourdomain.com/ and http://yourdomain.com/ ARE NOT THE SAME address. Just because most web servers are set to show the same content to both addresses does not mean that this has to be the case.

Technically anything before the first dot such as www. or news. or anything. are sub-domains and should be treated as separate entities. Internet Explorer in particular enforces this distinction. This is the reason that the issue is more prevalent in Internet Explorer.

What restrictions does this imply?

Certain javascript functions are not allowed - this is to prevent what is known as Cross Site Scripting - whereby code from one domain is executed on pages of another domain usually to expose some data that otherwise should be kept secret, for example to expose session ids or cookie values from one site to the operator of another site.

Joomla and the www. mismatch?

The issue manifests itself with javascript and cookie issues, so interactive scripts and login issues are the main symptoms. Examples include wysiwyg editors not loading or functioning correctly, or anything javascript dependent not loading. Here at JoomlaShack the most common issue our users complain of is a failure of our very own Flash JPG Rotator to function as expected.

How to tell if you have the problem?

If your wysiwyg editor, or flash rotator, or admin login doesn't work correctly try the other form of address - if it suddenly works with the other form then you have been bitten by the www mismatch.

How to correct the situation

The key to this issue with Joomla is to set the $mosConfig_live_site variable in configuration.php to one form of address and stick to it. Obviously you have to enforce this - which at a minimum means never publishing the alternative form of the address.

You can take this a step further if your server is the Apache web server. You can use settings in your .htaccess file to force requests for the alternative form of address to automatically redirect on to your chosen form of address.

To force a redirect to the none www. address try this:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [R=301, L]

To force a redirect to the www. version of the address try to ensure that the following lines are present in your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301, L]

Now explaining the purpose of a .htaccess file is well beyond the scope of this article - but as my target audience is newcomers I suppose a few words are in order.

A .htaccess file is a special server configuration file used by Apache web servers to allow users to override specific server settings on a folder by folder basis. Settings in a .htaccess file may be inherited by sub-folders (sub-directories) so one file in the 'root' of a site can apply to a whole site.

  • The file is just a plain text file and can be edited by any basic text editor - such as notepad - but NOT a word processor.
  • The correct name for this file is '.htaccess' (without he quotes). Note the leading dot followed by htaccess - nothing before that leading dot.
  • If you try to create a file with this name in windows you will struggle - the Windows Graphical User Interface doesn't like it - although dos doesn't have problems. Windows Explorer doesn't allow such file names.

How to create a .htaccess file - in Windows

Create a .htaccess file - Method 1

Create a new text file in Notepad and try to save it as .htaccess . If it works fine. If you struggle, or Notepad adds .txt to the end of the filename against your wishes then try this: when you do the 'Save As', try wrapping the filename in double quotes ".htaccess"

Create a .htaccess file - Method 2

save the file with any filename you want - open a 'dos prompt' or 'command prompt' in the folder where you saved the file. Then type the following line and hit enter:
ren example.txt .htaccess

Create a .htaccess file - Method 3

save the file with any old name, upload to the server using FTP software and then rename the file on the server.

Joomla ships with a sample .htaccess file which is used for Search Engine Friendly Url purposes. Joomla uses method 3 above - the file is named htaccess.txt and needs to be renamed before Search Engine Friendly Urls are activated. We can piggyback our commands into this existing file if it is in use (ie if it has been renamed '.htaccess'. If your site is already utilising a .htaccess file then all you need to do is simply place the last two lines of your chosen redirect instructions towards the top of the file but AFTER the line:
RewriteEngine On

There are many, many other things the .htaccess file can be used for whether with websites in general or with Joomla in particular - but the above information should at least make you more informed about:

  • the causes of the www. mismatch,
  • how to diagnose that you have been affected
  • how to resolve the issue through a simple edit of configuration.php
  • how to permanently fix the issue through a htaccess redirect

Further reading on .htaccess files

.htaccess for Apache 1.3
http://httpd.apache.org/docs/1.3/howto/htaccess.html

.htaccess for Apache 2.0
http://httpd.apache.org/docs/2.0/howto/htaccess.html

htaccess CheatSheet:
http://www.thejackol.com/htaccess-cheatsheet/

Your favourite search engine will also return many resources on the topic.

published in Joomla How To

RECENT POSTS