The WWW :
- First, http://www.example.com is an actual sub domain of example.com, even if it is most of the time defined by default exactly as the main domain.
The problem is, the domain will as well always work, so that one can always load example.com and http://www.example.com if nothing is done.
Here come the Search Engine Optimisation matter, those two are duplicates, and worst, by default, every URL of a site will have a duplicate, because you can always keep or get rid of the www.
The www sub domain is linked to the same hosting as the domain.
Some bots do try to get rid of the www to load pages, even if they did follow a link with the www. And people can post such links too, so that in the end, if you do nothing, you are very likely to find duplicate indexing in search engines results and to end up with smaller Page Ranking.
The solution is to redirect with a 301 http header to only use one of the two.
what to choose ?
- Internet is all about standard, Search Engines Bots do follow standards, or at least are built according to them. So the obvious choice here, is to always keep the www.
And it's not only about Bots understanding this is a main domain and not a sub (thus more important ?).
Did I say standards ? http://www.example.com vs example.com . Which one will have more weight do you think ?
PhpBB is not the only place to prefer www, almost every form able to auto create links will do it using a RegEx based on the www, no www, no auto active link
One would have to post http://example.com , which you will admit is less probable.
Some site even add the www in their sub domains, but it can become a bit long in the end, which is something to take care of as well in URLs.
The solutions :
- Apache mod Rewrite :
- Code: Select all
RewriteEngine on- Code: Select all
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [QSA,L,R=301]- Code: Select all
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [QSA,L,R=301]- Code: Select all
RewriteCond %{HTTP_HOST} !^(www|sub1|sub2|sub3)\.example\.com$ [NC]- Code: Select all
$req_uri = $_SERVER['REQUEST_URI'];
$req_domain = $_SERVER['HTTP_HOST'];
$sub = substr( $domaine, 0, strpos($domaine,".") );
if ($sub != 'www')
{
header("Status: 301 Moved Permanently", false, 301);
header("Location: http://www.example.com/$req_uri");
exit();
}
- As usual, Apache mod rewrite is the perfect solution.
The idea here is to first check if the www is present in the requested URL and if not to add it through a 301 http redirection. User won't even notice the difference, Bots will "know" that the www is the unique URL to use.
The problem here is several approaches are possible and working solution depends on some server settings.
First we can either test if the www is or is not present by checking if your domain URL is different from http://www.example.com or equal to example.com.
Then, since the "." is a special character for mod rewrite, we should be escaping it with an "\" but, I did see some examples on which it was not allowing the rule to work for all of the web site's sub folders.
These differences mostly comes from hosting companies building custom releases of Apache and mod rewrite.
In the end, one have to perform some quick testing with the following examples.
The proposed RewriteCond and RewriteRule should of course be placed in your root's .htaccess, right after :
First method : URL = example.com.
Note that if you experience problem with this code and your server, you can try getting rid of the "\", the $ and the [NC] in the RewriteCond.
The advantages of this method are, you won't mess with sub domains that could be physically hosted within the main domain ftp account.
Second method : URL !=www.example.com.
The same thing apply here withe the "\", the $ and the [NC] in the RewriteCond.
If for some reason this is the only working solution for your site and you have to deal with sub domains, then, you can just tweak the RewriteCond as follow :
And keep the rewriterule. Anything not showing up in the list will be redirected to http://www.example.com/uri with a 301 http header.
PHP redirection :
- For those not lucky enough to run Apache with mod rewrite, two solutions :
1) Change hosting
2) Try using the following php script
But this could mess up with some processes if not applied early enough. For phpBB, a good place should be in common.php, before the "?>".
You can also apply the same principles to force the URL not to use the www, even if it is certainly less interesting as far as Search Engine Optimization (SEO).

English |
French
News



