Joomla Errors and the www. Domain Mismatch

Many website builders experience problems with their site for a surprising reason: the www version of your site and the non-www version are the not the same address.

This is not a Joomla-specific issue, but it can cause problems with Joomla sites.

This issue can manifest itself as login failures, WYSIWYG editors failing to load or failing to save content, javascript execution halted with error messages.

In this blog post, you will learn what causes the www domain mismatch and what to do to avoid it.

What Causes This? and 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. When code from one domain is executed on pages of another domain.

Such techniques often deployed by malicious users to gain access to 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

This issue most commonly manifests itself with javascript and cookies. 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.

How to Tell if You Have This Problem?

If your WYSIWYG editor 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 $live_site variable in the configuration.php file 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 (.*)$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 (.*)$1 [R=301, L]

What is .htaccess File?

The .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. So one .htaccess file in the 'root' of a site can apply to the whole site.

  • The .htaccess 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 the quotes. Note the leading dot followed by htaccess, there is 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.

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, as ".htaccess".

Create a .htaccess file - Method 2

    • Save the file with any filename you want, for example, example.txt.
    • Open the 'command prompt' in the folder where you saved the file.
    • 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 the file to the server using FTP software.
  • 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.

You can piggyback your commands into this existing file if it is in use, i.e. if it has been renamed to .htaccess. If your site is already utilizing 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. Be it with websites in general or with Joomla in particular.

Hopefully, the above information made 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.

Additional Reading

About the author

Born from a Ukrainian mother and Russian father, Alex migrated to the United Kingdom in 1999. Alex is a self-taught Microsoft Certified Professional. He enjoys learning modern content management systems and helping web site administrators make the most of them.