PDA

View Full Version : Board Optimization - Enforce www preference in URL


jcodemasters
09-30-2008, 10:00 PM
Hello,
After an year I finally got some time to look at my poor board which is losing page rank in every google update. I am currently optimizing my forum, while doing this i found there was duplicate content issue in my forum. See this example

http://myvbforum.com Page rank 0
http://www.myvbforum.com Page rank 2
http://www.myvbforum.com/index.php Page rank 1

You can see from above urls all have same contents but different page rank also Google consider them different urls and those cause the duplicate contents problem.

In order to avoid duplicate contents issue you should add following code to your config.php on second line below this ini_set("max_execution_time", "240");

$web_home = 'http://www.REPLACE_WITH_YOUR_FORUM_URL.com';

if ( $_SERVER['REQUEST_URI'] == str_replace('http://' . $_SERVER['HTTP_HOST'], '', $web_home) . '/index.php' ) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $web_home . '/');
exit();
}
if ( strpos($_SERVER['HTTP_HOST'], 'www.') === 0 && strpos($web_home, 'http://www.') === false ) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://' . substr($_SERVER['HTTP_HOST'], 4) . $_SERVER['REQUEST_URI']);
exit();
} elseif ( strpos($_SERVER['HTTP_HOST'], 'www.') !== 0 && strpos($web_home, 'http://www.') === 0 ) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}

I have tested it in VB 3.6.4 and it works fine. I am not VB expert this could be a plugin, if you can make it then please upload here.

Have Fun

Milad
10-01-2008, 12:57 AM
In .htaccess


<IfModule mod_rewrite.c>
RewriteEngine On
# Rewrite for including www
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*)$ http://www.yourdomain.com/$1 [L,R=301]
</IfModule>

SEOvB
10-01-2008, 02:24 AM
Yea, not sure why you'd do it the way you did when a simple .htaccess would do

Also, google no longer treats those pages as duplicate content as it's pretty smart these days. You should find other reasons why you're losing pagerank

jcodemasters
10-01-2008, 02:51 AM
Its just method I described it here. Its up to vb users whether they use it or not. I am just sharing it.

P.s: index.php option is missing in htaccess and I think easy way is to use htaccess

dreads
10-02-2008, 01:29 AM
FRDS
Well not everyone runs apache ...

ryancooper
10-02-2008, 10:58 AM
In .htaccess


<IfModule mod_rewrite.c>
RewriteEngine On
# Rewrite for including www
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*)$ http://www.yourdomain.com/$1 [L,R=301]
</IfModule>

Cool tHanks!

Milad
10-05-2008, 10:39 AM
Try this

In .htaccess


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php http://www.yourdomain.com/ [L,R=301]
# Rewrite for including www
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*)$ http://www.yourdomain.com/$1 [L,R=301]
</IfModule>

Namaless
10-13-2008, 05:39 PM
I have choose to add into Plugins Manager and works correctly with BBURL vBulletin variable:

init_startup

$web_home = $vbulletin->options['bburl'];

if ( $_SERVER['REQUEST_URI'] == str_replace('http://' . $_SERVER['HTTP_HOST'], '', $web_home) . '/index.php' )
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $web_home . '/');
exit();
}

if ( strpos($_SERVER['HTTP_HOST'], 'www.') === 0 && strpos($web_home, 'http://www.') === false )
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://' . substr($_SERVER['HTTP_HOST'], 4) . $_SERVER['REQUEST_URI']);
exit();
}
else if ( strpos($_SERVER['HTTP_HOST'], 'www.') !== 0 && strpos($web_home, 'http://www.') === 0 )
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}


No need any modifications or settings.

Regards.