Just reviewing some sites in my portfolio, and I notice that a CubeCart installation on a shared host is broken. Oh dear…
Deprecated: Function set_magic_quotes_runtime() is deprecated in /path/to/domain/shop/ini.inc.php on line 114Warning: ini_set(): Cannot change zlib.output_compression - headers already sent in /path/to/domain/shop/ini.inc.php on line 118 Warning: Cannot modify header information - headers already sent by (output started at /path/to/domain/shop/ini.inc.php:114) in /path/to/domain/shop/index_enc_ion.php on line 31 Warning: Cannot modify header information - headers already sent by (output started at /path/to/domain/shop/ini.inc.php:114) in /path/to/domain/shop/index_enc_ion.php on line 32Deprecated: Function eregi() is deprecated in /path/to/domain/shop/includes/functions.inc.php on line 408
Ah, great. Without warning, we’ve been upgraded to PHP 5.3
Thanks for that…
Anyway, it’s easily solved.
With 5.3 a new error level has been introduced – E_DEPRECATED, so it’s easy to suppress deprecated errors:
In your scripts:
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
In the case of CubeCart 4 this can be acheived in ini.inc.php line 101.
In php.ini:
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
in .htaccess:
php_value error_reporting 1
.htaccess requires the correct integer value equivalent of your chosen reporting level – these are a touch obscure, but setting it to 1 means report fatal run-time errors and unrecoverable errors, which will do the trick.
Many moons ago, one of my webmastery guru’s told me that he considered www to be antiquated bullshit in a domain name – a waste of time and space. I agreed with his logic, and have supported the cause ever since.
The issue arose today when a client noted an issue with his Joomla sites – if you login on http://domain.tld, then click on a link that takes you to http://www.domain.tld, you will no longer be logged in, as the cookies are set for different domain names. To the casual user with or without www is the same thing, but as far as t’internet is concerned, www.domain.tld is actually a SUBDOMAIN of domain.tld.
It is also an issue for SEO and indexing, because as far as search engines are concerned, the ‘two’ sites are counted differently, meaning that links to one or t’other do not count towards a single total for page rank. It also means that the ‘two’ are considered duplicate content, reducing the perceived value of your data, especially as they both share an IP address so it looks to the search engines as if you are engaging in blackhat SEO techniques. This was certainly true in the past, and while I would have thought that search engines would be quite beyond such blatant foolishness, it’s best to play safe.
Luckily this is very easily cured.
If you ARE using Joomla and are not very technically minded, there is an SEO Canonicalisation Plugin plugin that will sort you out.
Wait, canonicalisation? REALLY? What kind of etymological rape have you people committed there? Can I suggest, I dunno, ‘canonifcation’ instead? But wait, it’s actually a real, technical term! It even has US and Anglicised versions, like a proper grown-up word and everything. Still, correct or not, it’s damn ugly, and blatantly coined by an American. However, it does not mean ‘to adjust the topography of an object in such a way as to cause it to resemble a big gun’.
Tragic that.
Haaaanyway, back to the point:
I personally would rather have less crap installed in Joomla, and want a solution that is not dependant on it.
.htaccess to the rescue! Feel the power of the rewrite rule!
What fun.
In your .htaccess file, ensure that you have ‘RewriteEngine On’ and add the necessary RewriteCond and RewriteRule. The rule tells the browser (and search engines) that the change is a 301 redirect, a very healthy way to go about things – html redirects, by contrast, being potentially indicative of blackhat behaviour.
Redirect www.domain to domain in .htaccess
RewriteEngine On# Redirect http://www.domain.tld requests to http://domain.tldRewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Bang. And the dirt is gone…
So, whagwandere? Well, RewriteEngine uses Regular Expressions (RegEx) to define the condition and the rule.
The Condition:
The condition says ONLY apply the following rule IF these conditions are met.
First we define variables:
%{HTTP_HOST} – A predifined variable meaning this domain name and tld without www or trailing slash
Then we define the conditions to match:
^www. – An http request (which is all .htaccess will process) that starts (^ = start of a match) with the string www followed by a period (. – .= any character – the period is preceded by a backslash to ‘escape’ it, meaning ignore any special meaning of the following character)
(.*)$ – Any number (* = any number) of any characters (. = any character). The parentheses creates a group ensuring the asterisk only applies to the preceding period, not a larger string, and also creates a backreference. $ indicates the end of the match.
[NC] – A flag telling Apache the rule is not case-sensitive
(.*) is an incredibly greedy regular expression, and should normally be avoided, but it is the right thing in this case, as we DO want to match absolutely ANYTHING after the www. and it is safe to use in this situation because we know precisely the nature of the input.
The Rule:
The rule consists of two parts, the match and the replacement. The match is pretty simple:
^(.*)$ – The greediest Regex EVER! It matches anything and everything. As we have already defined our condition, we know we want to replace EVERYTHING. It says start of match(^) followed by any number of any characters ((.*)) before the end of the match ($).
The replacement is slightly more complex:
http:// – string literal.
%1 – the first (in our case only) varable.
/ – string literal.
$1 – Backreference 1 defined by the parentheses in the condition regex.
[R=301,L] – Apache flags – R indicates which http status code to return, in this case 301 (Redirect: Permanently moved). L indicates that Apache should apply no more rules once this rule has bee applied.
What’s that? You want to direct domain to www.domain? Nob off. That’s not helping the cause. GIYF.